group_trim {dplyr} | R Documentation

## Trim grouping structure

### Description

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_drops(.tbl))

### Arguments

`.tbl` | A grouped data frame
`.drop` | See `group_by()`

### Details

### Value

A grouped data frame

### See Also

Other grouping functions: `group_by_all`, `group_by`, `group_indices`, `group_keys`, `group_map`, `group_nest`, `group_rows`, `group_size`, `groups`

### Examples

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

[Package dplyr version 0.8.0.1 Index]