I'm trying to use group_by inside a function, with the grouping criteria being an input of the function. Right now I have it set up as so:
x <- function(data, grouping_vector) {
data %>%
group_by_(grouping_vector) %>%
summarise(n = n()) -> output
output
}
... but when I try to use this function on a list of multiple grouping items as so:
example <- x(data = my_data, grouping_vector = c(col1, col2))
it fails. Is there a way to feed multiple group_by subjects into that function? I know you can simply separate multiple columns by a comma normally, but I don't know how I would do that in a function.
Thanks