if (interactive() && require("dplyr")) {
withAutoprint({
set.seed(50)
years <- sample(0:90, 100, replace = TRUE)
months <- ifelse(years < 2, sample(0:23, 100, replace = TRUE), NA)
days <- ifelse(years < 2 & months < 2, sample(0:30, 100, replace = TRUE), NA)
dat <- data.frame(age_years = years, age_months = months, age_days = days)
ages <- dat %>%
select(starts_with("age")) %>%
mutate(age_years = age_categories(age_years, breakers = c(0, 5, 10, 15, 20))) %>%
mutate(age_months = age_categories(age_months, breakers = c(0, 5, 10, 15, 20))) %>%
mutate(age_days = age_categories(age_days, breakers = c(0, 5, 15)))
ages %>%
group_age_categories(years = age_years, months = age_months, days = age_days) %>%
pull(age_category) %>%
table()
})
}
Run the code above in your browser using DataLab