1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/group-nest.R
\name{group_nest}
\alias{group_nest}
\title{Nest a tibble using a grouping specification}
\usage{
group_nest(.tbl, ..., .key = "data", keep = FALSE)
}
\arguments{
\item{.tbl}{A tbl}
\item{...}{Grouping specification, forwarded to \code{\link[=group_by]{group_by()}}}
\item{.key}{the name of the list column}
\item{keep}{Should the grouping columns be kept in the list column.}
}
\value{
A tbl with one row per unique combination of the grouping variables.
The first columns are the grouping variables, followed by a list column of tibbles
with matching rows of the remaining columns.
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Nest a tibble using a grouping specification
}
\section{Lifecycle}{
\code{group_nest()} is not stable because \code{\link[tidyr:nest]{tidyr::nest(.by =)}}
provides very similar behavior. It may be deprecated in the future.
}
\section{Grouped data frames}{
The primary use case for \code{\link[=group_nest]{group_nest()}} is with already grouped data frames,
typically a result of \code{\link[=group_by]{group_by()}}. In this case \code{\link[=group_nest]{group_nest()}} only uses
the first argument, the grouped tibble, and warns when \code{...} is used.
}
\section{Ungrouped data frames}{
When used on ungrouped data frames, \code{\link[=group_nest]{group_nest()}} forwards the \code{...} to
\code{\link[=group_by]{group_by()}} before nesting, therefore the \code{...} are subject to the data mask.
}
\examples{
#----- use case 1: a grouped data frame
iris \%>\%
group_by(Species) \%>\%
group_nest()
# this can be useful if the grouped data has been altered before nesting
iris \%>\%
group_by(Species) \%>\%
filter(Sepal.Length > mean(Sepal.Length)) \%>\%
group_nest()
#----- use case 2: using group_nest() on a ungrouped data frame with
# a grouping specification that uses the data mask
starwars \%>\%
group_nest(species, homeworld)
}
\seealso{
Other grouping functions:
\code{\link{group_by}()},
\code{\link{group_map}()},
\code{\link{group_split}()},
\code{\link{group_trim}()}
}
\concept{grouping functions}
\keyword{internal}
|