Skip to contents

nest_unite() is used to combine multiple columns into one in a column of nested data frames.

Usage

nest_unite(
  .data,
  .nest_data,
  col,
  ...,
  sep = "_",
  remove = TRUE,
  na.rm = FALSE
)

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

col

The name of the new column, as a string or symbol.

This argument is passed by expression and supports quasiquotation (you can unquote strings and symbols). The name is captured from the expression with rlang::ensym() (note that this kind of interface where symbols do not represent actual objects is now discouraged in the tidyverse; we support it here for backward compatibility).

...

Columns to unite.

sep

Separator to use between values.

remove

If TRUE, remove input columns from output data frame.

na.rm

If TRUE, missing values will be removed prior to uniting each value.

Value

An object of the same type as .data. Each object in the column .nest_data

will have a new column created as a combination of existing columns.

Details

nest_unite() is a wrapper for tidyr::unite() and maintains the functionality of unite() within each nested data frame. For more information on unite() please refer to the documentation in 'tidyr'.

See also

Examples

set.seed(123)
gm <- gapminder::gapminder 
gm_nest <- gm %>% tidyr::nest(country_data = -continent)

gm_nest %>% 
  nest_unite(country_data, 
             col = comb, 
             year, 
             pop)
#> # A tibble: 5 × 2
#>   continent country_data      
#>   <fct>     <list>            
#> 1 Asia      <tibble [396 × 4]>
#> 2 Europe    <tibble [360 × 4]>
#> 3 Africa    <tibble [624 × 4]>
#> 4 Americas  <tibble [300 × 4]>
#> 5 Oceania   <tibble [24 × 4]>