Learn R Programming

dplyr (version 1.0.10)

group_trim: Trim grouping structure

Description

[Experimental] 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.

Usage

group_trim(.tbl, .drop = group_by_drop_default(.tbl))

Value

A grouped data frame

Arguments

.tbl

A grouped data frame

.drop

See group_by()

See Also

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

Examples

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

Run the code above in your browser using DataLab