nest_select: Subset columns in nested data frames using their names and...

View source: R/nest_select.R

nest_selectR Documentation

Subset columns in nested data frames using their names and types

Description

nest_select() selects (and optionally renames) variables in nested data frames, using a concise mini-language that makes it easy to refer to variables based on their name (e.g., a:f selects all columns from a on the left to f on the right). You can also use predicate functions like is.numeric to select variables based on their properties.

Usage

nest_select(.data, .nest_data, ...)

Arguments

.data

A data frame, data frame extension (e.g., a tibble), or a lazy data frame (e.g., from dbplyr or dtplyr).

.nest_data

A list-column containing data frames

...

One or more unquoted expressions separated by commas. Variable names can be used if they were positions in the data frame, so expressions like x:y can be used to select a range of variables.

Details

nest_select() is largely a wrapper for dplyr::select() and maintains the functionality of select() within each nested data frame. For more information on select(), please refer to the documentation in dplyr.

Value

An object of the same type as .data. Each object in the column .nest_data will also be of the same type as the input. Each object in .nest_data has the following properties:

  • Rows are not affect.

  • Output columns are a subset of input columns, potentially with a different order. Columns will be renamed if new_name = old_name form is used.

  • Data frame attributes are preserved.

  • Groups are maintained; you can't select off grouping variables.

See Also

Other single table verbs: nest_arrange(), nest_filter(), nest_mutate(), nest_rename(), nest_slice(), nest_summarise()

Examples

gm_nest <- gapminder::gapminder %>% tidyr::nest(country_data = -continent)

gm_nest %>% nest_select(country_data, country, year, pop)
gm_nest %>% nest_select(country_data, where(is.numeric))

nplyr documentation built on Feb. 16, 2023, 7:24 p.m.