Learn R Programming

tidyfst (version 0.7.7)

unite_dt: Unite multiple columns into one by pasting strings together

Description

Convenience function to paste together multiple columns into one. Analogous to tidyr::unite.

Usage

unite_dt(data, united_colname, ..., sep = "_", remove = TRUE, na.rm = FALSE)

Arguments

data

A data frame.

united_colname

The name of the new column, string only.

...

A selection of columns. If want to select all columns, pass "" to the parameter. See example.

sep

Separator to use between values.

remove

If TRUE, remove input columns from output data frame.

na.rm

If TRUE, missing values would be merged into NA, otherwise NA is treated as character "NA". This is different from tidyr.

See Also

unite,separate_dt

Examples

Run this code
# NOT RUN {
df <- expand.grid(x = c("a", NA), y = c("b", NA))
df

# Treat missing value as character "NA"
df %>% unite_dt("z", x:y, remove = FALSE)
# Treat missing value as NA
df %>% unite_dt("z", x:y, na.rm = TRUE, remove = FALSE)
df %>%
  unite_dt("xy", x:y)

# Select all columns
iris %>% unite_dt("merged_name","")
# }

Run the code above in your browser using DataLab