nest_separate {nplyr} | R Documentation |
Separate a character column into multiple columns in a column of nested data frames
Description
nest_separate()
is used to separate a single character column into multiple
columns using a regular expression or a vector of character positions in a
list of nested data frames.
Usage
nest_separate(
.data,
.nest_data,
col,
into,
sep = "[^[:alnum:]]+",
remove = TRUE,
convert = FALSE,
extra = "warn",
fill = "warn",
...
)
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 |
Column name or position within. Must be present in all data frames
in This argument is passed by expression and supports quasiquotation (you can unquote column names or column positions). |
into |
Names of new variables to create as character vector.
Use |
sep |
Separator between columns. If character, If numeric, |
remove |
If |
convert |
If NB: this will cause string |
extra |
If
|
fill |
If
|
... |
Additional arguments passed on to |
Details
nest_separate()
is a wrapper for tidyr::separate()
and maintains the functionality
of separate()
within each nested data frame. For more information on separate()
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 the specified column split according to the regular expression or
the vector of character positions.
See Also
Other tidyr verbs:
nest_drop_na()
,
nest_extract()
,
nest_fill()
,
nest_replace_na()
,
nest_unite()
Examples
set.seed(123)
gm <- gapminder::gapminder %>% mutate(comb = paste(continent,year,sep = "-"))
gm_nest <- gm %>% tidyr::nest(country_data = -continent)
gm_nest %>%
nest_separate(.nest_data = country_data,
col = comb,
into = c("var1","var2"),
sep = "-")