In the case where Tibet is grouped by several variables in dplyr, is there a way to remove one grouping variable other than re-setting groups without this variable? I think it will be something like group_by(df, -var, add = TRUE), although it does not work.
Example:
library(dplyr)
# Works
mtcars %>%
# Original groups
group_by(cyl, gear, carb) %>%
# New groups
group_by(cyl, gear) %>%
group_vars()
# [1] "cyl" "gear"
# Doesn't work
mtcars %>%
# Original groups
group_by(cyl, gear, carb) %>%
# New groups
group_by(-carb, add = TRUE) %>%
group_vars()
# [1] "cyl" "gear" "carb" "-carb"
This is obviously a trivial example. In my actual use case, there are many conditional groupings based on user input, and I would just like to drop one group at some point in the function and leave the rest.
source
share