Paste together multiple columns into one. Wrapper arround
unite() that supports standard and non standard
evaluation.
df_unite(data, col, ..., vars = NULL, sep = "_", remove = TRUE, na.rm = FALSE)
df_unite_factors(
data,
col,
...,
vars = NULL,
sep = "_",
remove = TRUE,
na.rm = FALSE
)a data frame
the name of the new column as a string or a symbol.
a selection of columns. One or more unquoted expressions (or variable names) separated by commas.
a character vector containing the column names of interest.
Separator to use between values.
If TRUE, remove input columns from output data frame.
If TRUE, missing values will be removed prior to uniting
each value.
df_unite(): Unite multiple columns into one.
df_unite_factors(): Unite factor columns. First, order factors levels then
merge them into one column. The output column is a factor.
# Non standard evaluation
head(ToothGrowth) %>%
df_unite(col = "dose_supp", dose, supp)
#> len dose_supp
#> 1 4.2 0.5_VC
#> 2 11.5 0.5_VC
#> 3 7.3 0.5_VC
#> 4 5.8 0.5_VC
#> 5 6.4 0.5_VC
#> 6 10.0 0.5_VC
# Standard evaluation
head(ToothGrowth) %>%
df_unite(col = "dose_supp", vars = c("dose", "supp"))
#> len dose_supp
#> 1 4.2 0.5_VC
#> 2 11.5 0.5_VC
#> 3 7.3 0.5_VC
#> 4 5.8 0.5_VC
#> 5 6.4 0.5_VC
#> 6 10.0 0.5_VC