https://github.com/hadley/dplyr
Raw File
Tip revision: 7681a076724805948a9d668d6281377f39f0a63b authored by Romain Francois on 04 December 2020, 18:46:57 UTC
ungroup() before vec_slice()
Tip revision: 7681a07
group_trim.Rd
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/group_trim.R
\name{group_trim}
\alias{group_trim}
\title{Trim grouping structure}
\usage{
group_trim(.tbl, .drop = group_by_drop_default(.tbl))
}
\arguments{
\item{.tbl}{A \link[=grouped_df]{grouped data frame}}

\item{.drop}{See \code{\link[=group_by]{group_by()}}}
}
\value{
A \link[=grouped_df]{grouped data frame}
}
\description{
\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}
Drop unused levels of all factors that are used as grouping variables,
then recalculates the grouping structure.

\code{group_trim()} is particularly useful after a \code{\link[=filter]{filter()}} that is intended
to select a subset of groups.
}
\examples{
iris \%>\%
  group_by(Species) \%>\%
  filter(Species == "setosa", .preserve = TRUE) \%>\%
  group_trim()
}
\seealso{
Other grouping functions: 
\code{\link{group_by}()},
\code{\link{group_map}()},
\code{\link{group_nest}()},
\code{\link{group_split}()}
}
\concept{grouping functions}
back to top