lapply_rows | R Documentation |
data.frame
-like object and concatenate the results back to tibble
or data.frame
.Inside a FUN
, a row of df
will be available as a list or scdrake_list()
(default).
The FUN
must return a named list for a proper concatenation of the results.
The named list can also contain elements of a length other than one, which are then wrapped in list()
.
lapply_rows(df, as_scdrake_list = TRUE, return_tibble = TRUE, FUN, ...)
df |
A |
as_scdrake_list |
A logical scalar: if |
return_tibble |
If |
FUN |
A function to apply over |
... |
Additional arguments passed to |
tibble
or data.frame
according to the return_tibble
parameter.
library(magrittr)
fn <- function(row_list) {
row_list$cyl_2 <- row_list$cyl**2
row_list$colors <- c("red", "green", "blue")
row_list$sublist <- mtcars[1:5, 1:5]
return(row_list)
}
df <- lapply_rows(mtcars, FUN = fn)
head(df)
df2 <- lapply_rows(mtcars, return_tibble = FALSE, FUN = fn)
head(df2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.