powered by
Drop unused levels of all factors that are used as grouping variables, then recalculates the grouping structure.
group_trim() is particularly useful after a filter() that is intended to select a subset of groups.
group_trim()
filter()
group_trim(.tbl, .drop = group_by_drop_default(.tbl))
A grouped data frame
See group_by()
group_by()
Other grouping functions: group_by(), group_map(), group_nest(), group_split()
group_map()
group_nest()
group_split()
iris %>% group_by(Species) %>% filter(Species == "setosa", .preserve = TRUE) %>% group_trim()
Run the code above in your browser using DataLab