nest_unite: Unite multiple columns into one in a column of nested data...

View source: R/nest_unite.R

nest_uniteR Documentation

Unite multiple columns into one in a column of nested data frames

Description

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.

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

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.

See Also

Other tidyr verbs: nest_drop_na(), nest_extract(), nest_fill(), nest_replace_na(), nest_separate()

Examples

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

gm_nest %>% 
  nest_unite(.nest_data = country_data, 
             col = comb, 
             year, 
             pop)

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