nest {tidyr} | R Documentation |
There are many possible ways one could choose to nest columns inside a
data frame. nest()
creates a list of data frames containing all
the nested variables: this seems to be the most useful form in practice.
nest(data, ..., .key = data)
data |
A data frame. |
... |
Specification of columns to nest. Use bare variable names.
Select all variables between x and z with |
.key |
The name of the new column. |
unnest
for the inverse operation.
nest_
for a version that uses regular evaluation
and is suitable for programming with.
library(dplyr) iris %>% nest(-Species) chickwts %>% nest(weight) if (require("gapminder")) { gapminder %>% group_by(country, continent) %>% nest() gapminder %>% nest(-country, -continent) }