hi I have a function I create below:
output_function <- function(var1, var2) {
data %>%
group_by(!!sym(var1), !!sym(var2)) %>%
summarize(counts = n()) %>%
ungroup() %>%
mutate(percent = counts / sum(counts))
}
I want to run this function with several variables as seen below.
cats_color <- output_function("cats_counts", "CATCOLOR")
cats_age <- output_function("cats_counts", "CATAGE")
dogs_color <- output_function("dogs_counts", "DOGCOLOR")
dogs_age <- output_function("dogs_counts", "DOGAGE")
monkeys_color <- output_function("monkeys_counts", "MONKEYCOLOR")
monkeys_age <- output_function("monkeys_counts", "MONKEYAGE")
...
and so on and so forth
is there a shorter way to do this maybe with a loop? I do want to make a separate dataset for each one. thank you.