nest_arrange()
orders the rows of nested data frames by the values of
selected columns.
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
- ...
Variables, or functions of variables. Use
dplyr::desc()
to sort a variable in descending order.- .by_group
If
TRUE
, will sort first by grouping variable. Applies to grouped data frames only.
Value
An object of the same type as .data
. Each object in the column .nest_data
will be also of the same type as the input. Each object in .nest_data
has
the following properties:
All rows appear in the output, but (usually) in a different place.
Columns are not modified.
Groups are not modified.
Data frame attributes are preserved.
Details
nest_arrange()
is largely a wrapper for dplyr::arrange()
and maintains
the functionality of arrange()
within each nested data frame. For more
information on arrange()
, please refer to the documentation in
dplyr
.
See also
Other single table verbs:
nest_filter()
,
nest_mutate()
,
nest_rename()
,
nest_select()
,
nest_slice()
,
nest_summarise()
Examples
gm_nest <- gapminder::gapminder %>% tidyr::nest(country_data = -continent)
gm_nest %>%
nest_arrange(country_data, pop)
#> # A tibble: 5 × 2
#> continent country_data
#> <fct> <list>
#> 1 Asia <tibble [396 × 5]>
#> 2 Europe <tibble [360 × 5]>
#> 3 Africa <tibble [624 × 5]>
#> 4 Americas <tibble [300 × 5]>
#> 5 Oceania <tibble [24 × 5]>
gm_nest %>%
nest_arrange(country_data, desc(pop))
#> # A tibble: 5 × 2
#> continent country_data
#> <fct> <list>
#> 1 Asia <tibble [396 × 5]>
#> 2 Europe <tibble [360 × 5]>
#> 3 Africa <tibble [624 × 5]>
#> 4 Americas <tibble [300 × 5]>
#> 5 Oceania <tibble [24 × 5]>