Learn R Programming

SignalY (version 1.1.1)

apply_to_columns: Apply Function to Matrix Columns

Description

Applies a univariate filtering or transformation function to each column of a matrix and returns a consolidated data frame. This utility enables batch processing of panel data where each column represents a different variable or series.

Usage

apply_to_columns(X, FUN, extract = NULL, ..., verbose = FALSE)

Value

A data frame with the same number of rows as X, containing the processed output for each column.

Arguments

X

Matrix or data frame where each column is a series to process.

FUN

Function to apply to each column. Must accept a numeric vector and return either a numeric vector of the same length or a list with a named element (specified by extract).

extract

Character string specifying which element to extract from the function output if it returns a list. Default is NULL (use raw output).

...

Additional arguments passed to FUN.

verbose

Logical indicating whether to print progress messages.

Examples

Run this code
X <- matrix(rnorm(200), ncol = 4)
colnames(X) <- c("A", "B", "C", "D")
result <- apply_to_columns(X, function(x) cumsum(x))

Run the code above in your browser using DataLab