Created
March 11, 2022 15:15
-
-
Save jrosell/b95918ae70dfad3d2abb8357802ae01a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Execute f for each row of df | |
#' | |
#' @param df data.frame | |
#' @param f function | |
#' @return A data.frame with the result of executin g for each row of df. | |
#' @examples | |
#' row_split_map( | |
#' tibble(x = c(1, 2), y = c(2, 3)), | |
#' function(df) { | |
#' df %>% mutate( | |
#' sum = df$x[[1]] + df$y[[1]] | |
#' ) | |
#' } | |
#' ) | |
row_split_map <- function(df, f) { | |
df %>% | |
group_by(.row_split_map_id = row_number()) %>% | |
group_split() %>% | |
map_dfr(f) %>% | |
select(-.row_split_map_id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment