group_trim function

Trim grouping structure

Trim grouping structure

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(.tbl, .drop = group_by_drop_default(.tbl))

Arguments

  • .tbl: A grouped data frame
  • .drop: See group_by()

Returns

A grouped data frame

Examples

iris %>% group_by(Species) %>% filter(Species == "setosa", .preserve = TRUE) %>% group_trim()

See Also

Other grouping functions: group_by(), group_map(), group_nest(), group_split()

  • Maintainer: Hadley Wickham
  • License: MIT + file LICENSE
  • Last published: 2023-11-17

Downloads (last 30 days):