gm_nest <- gapminder::gapminder %>% tidyr::nest(country_data = -continent)
# grouping doesn't change .nest_data, just .nest_data class:
gm_nest_grouped <-
gm_nest %>%
nest_group_by(country_data, year)
gm_nest_grouped
# It changes how it acts with other nplyr verbs:
gm_nest_grouped %>%
nest_summarise(
country_data,
lifeExp = mean(lifeExp),
pop = mean(pop),
gdpPercap = mean(gdpPercap)
)
# ungrouping removes variable groups:
gm_nest_grouped %>% nest_ungroup(country_data)
Run the code above in your browser using DataLab