Is there a tidyeval way to group_by() all columns in a data frame EXCEPT for the ones you don’t want grouped? I often need to come up with shares over 1 dimension, so I use group_by_() to select all names except the ones I want.
This is useful for me for programming as I don’t always know the names of the other columns in the data frame. My current method seems inefficient, though.
In the example below, I group by all columns except Sex and Freq (the data). This returns the shares by sex, grouped by Hair and Eye.
as.data.frame(HairEyeColor) %>% group_by_(.dots = as.list(names(.)[!(names(.) %in% c("Sex", "Freq"))])) %>% mutate(share = Freq / sum(Freq)) %>% ungroup()