Learn R Programming

tidytable (version 0.10.2)

unite.: Unite multiple columns by pasting strings together

Description

Convenience function to paste together multiple columns into one.

Usage

unite.(.df, col = ".united", ..., sep = "_", remove = TRUE, na.rm = FALSE)

Arguments

.df

A data.frame or data.table

col

Name of the new column, as a string.

...

Selection of columns. If empty all variables are selected. tidyselect compatible.

sep

Separator to use between values

remove

If TRUE, removes input columns from the data.table.

na.rm

If TRUE, NA values will be not be part of the concatenation

Examples

Run this code
df <- tidytable(
    a = c("a", "a", "a"),
    b = c("b", "b", "b"),
    c = c("c", "c", NA)
)

df %>%
  unite("new_col", b, c)

df %>%
  unite("new_col", where(is.character))

df %>%
  unite("new_col", b, c, remove = FALSE)

df %>%
  unite("new_col", b, c, na.rm = TRUE)

df %>%
  unite()

Run the code above in your browser using DataLab