fmapg | R Documentation |
Applies a function '.f' to each group of rows in a data frame '.df', where grouping is defined by one or more variables in 'by'. Each group is passed as a data frame to '.f'. Supports parallelism and optional progress display.
fmapg(.df, .f, by, ncores = NULL, pb = FALSE, ...)
.df |
A data frame to group and apply the function over. |
.f |
A function to apply to each group. The function should accept a data frame (a group). |
by |
A character vector of column names in '.df' used for grouping. |
ncores |
Integer. Number of cores to use for parallel processing. Default is 'NULL' (sequential). |
pb |
Logical. Whether to show a progress bar. Default is 'FALSE'. |
... |
Additional arguments passed to '.f'. |
A list of results, one for each group defined by 'by'.
# Group-wise mean of Sepal.Length in iris dataset
fmapg(iris, function(df) mean(df$Sepal.Length), by = "Species")
# Group-wise model fitting with progress and parallelism
fmapg(mtcars, function(df) lm(mpg ~ wt, data = df), by = "cyl", ncores = 2, pb = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.