unite: Unite Multiple Columns Into One

Description Usage Arguments Value Examples

View source: R/unite.R

Description

Convenience function to paste together multiple columns.

Usage

1
unite(data, col, ..., sep = "_", remove = TRUE, na.rm = FALSE)

Arguments

data

A data.frame.

col

character(1) or symbol(1). The name of the new column.

...

The columns to unite.

sep

character(1). Separator to use between the values.

remove

logical(1). If TRUE, remove the input columns from the output data.frame.

na.rm

logical(1). If TRUE, missing values will be remove prior to uniting each value.

Value

A data.frame with the columns passed via ... pasted together in a new column.

Examples

1
2
3
4
5
6
df <- data.frame(x = c("a", "a", NA, NA), y = c("b", NA, "b", NA))
df

df %>% unite("z", x:y, remove = FALSE)
# To remove missing values:
df %>% unite("z", x:y, na.rm = TRUE, remove = FALSE)

poorman documentation built on March 28, 2021, 5:05 p.m.