Learn R Programming

nplyr (version 0.2.0)

nest_relocate: Change column order within a nested data frame

Description

nest_relocate() changes column positions within a nested data frame, using the same syntax as nest_select() or dplyr::select() to make it easy to move blocks of columns at once.

Usage

nest_relocate(.data, .nest_data, ..., .before = NULL, .after = NULL)

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 affected.

  • The same columns appear in the output, but (usually) in a different place.

  • Data frame attributes are preserved.

  • Groups are not affected.

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

...

Columns to move.

.before, .after

Destination of columns selected by .... Supplying neither will move columns to the left-hand side; specifying both is an error.

Details

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

Examples

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

gm_nest %>% nest_relocate(country_data, year)
gm_nest %>% nest_relocate(country_data, pop, .after = year)

Run the code above in your browser using DataLab