Skip to content

Instantly share code, notes, and snippets.

@b-rodrigues
Created April 9, 2020 10:57
Show Gist options
  • Save b-rodrigues/26eaf0820930f0105d70b344a4038ee5 to your computer and use it in GitHub Desktop.
Save b-rodrigues/26eaf0820930f0105d70b344a4038ee5 to your computer and use it in GitHub Desktop.
map_filter <- function(dataset, variable, list_values, rbind = FALSE){
variable <- enquo(variable)
for_one_dataset <- function(dataset, variable, value){
dataset %>%
filter((!!variable) == value)
}
if (rbind) {
mapfun <- purrr::map_df
} else {
mapfun <- purrr::map
}
mapfun(list_values, for_one_dataset, dataset = dataset, variable = variable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment