Learn R Programming

tidyr (version 0.6.3)

nest: Nest repeated values in a list-variable.

Description

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.

Usage

nest(data, ..., .key = data)

Arguments

data

A data frame.

...

Specification of columns to nest. Use bare variable names. Select all variables between x and z with x:z, exclude y with -y. For more options, see the select documentation.

.key

The name of the new column.

See Also

unnest for the inverse operation.

nest_ for a version that uses regular evaluation and is suitable for programming with.

Examples

Run this code
# NOT RUN {
library(dplyr)
iris %>% nest(-Species)
chickwts %>% nest(weight)

if (require("gapminder")) {
  gapminder %>%
    group_by(country, continent) %>%
    nest()

  gapminder %>%
    nest(-country, -continent)
}
# }

Run the code above in your browser using DataLab