fmapr | R Documentation |
Applies a function '.f' to each row of a data frame '.df', with optional parallelism and progress bar. Each row is converted to a named list before being passed to '.f', enabling flexible access to variables by name.
fmapr(.df, .f, ncores = NULL, pb = FALSE, ...)
.df |
A data frame whose rows will be iterated over. |
.f |
A function applied to each row, which receives a named list. |
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'. |
A list of results returned by applying '.f' to each row as a list.
df <- data.frame(name = c("Mister", "Hipster"), age = c(30, 25))
# Create personalized messages
fmapr(df, function(row) paste(row$name, "is", row$age, "years old"))
# Row-wise model formulas
formulas <- data.frame(
response = c("y1", "y2"),
predictor = c("x1", "x2"),
stringsAsFactors = FALSE
)
fmapr(formulas, function(row) {
reformulate(row$predictor, row$response)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.