How to optimize case_when in a function?
问题 I would like to write a function that creates a binning variable based on some raw data. Specifically, I have a dateset with the age values for each respondent and I would like to write a function that classifies that person into an age group, where the age group is a parameter of that function. This is what I started with: data <- data.frame(age = 18:100) foo <- function(data, brackets = list(18:24, 25:34, 35:59)) { require(tidyverse) tmp <- data %>% drop_na(age) %>% mutate(age_bracket =