Learn R Programming

functionals (version 0.5.0)

fmapc: Apply a function column-wise with name access and parallelism

Description

Applies a function `.f` to each column of a data frame `.df`. Each call receives both the column vector and its name, enabling name-aware column processing. Supports parallel execution and progress display.

Usage

fmapc(.df, .f, ncores = NULL, pb = FALSE, ...)

Value

A list of results obtained by applying `.f` to each column of `.df`.

Arguments

.df

A data frame whose columns will be iterated over.

.f

A function that takes two arguments: the column vector and its name.

ncores

Integer. Number of cores to use for parallel processing. Default is `NULL` (sequential).

pb

Logical. Whether to display a progress bar. Default is `FALSE`.

...

Additional arguments passed to `.f`.

Examples

Run this code
df <- data.frame(a = 1:3, b = 4:6)

# Apply a function that returns column mean and name
fmapc(df, function(x, name) list(mean = mean(x), var = var(x), name = name))

# With progress and parallel execution
# \donttest{
fmapc(df, function(x, name) mean(x), ncores = 2, pb = TRUE)
# }

Run the code above in your browser using DataLab