Learn R Programming

tidyr (version 0.6.0)

unite: Unite multiple columns into one.

Description

Convenience function to paste together multiple columns into one.

Usage

unite(data, col, ..., sep = "_", remove = TRUE)

Arguments

data
A data frame.
col
(Bare) name of column to add
...
Specification of columns to unite. Use bare variable names. Select all variables between x and z with x:z, exclude y with -y. For more options, see the select documentation.
sep
Separator to use between values.
remove
If TRUE, remove input columns from output data frame.

See Also

separate(), the complement.

unite_ for a version that uses regular evaluation and is suitable for programming with.

Examples

Run this code
library(dplyr)
unite_(mtcars, "vs_am", c("vs","am"))

# Separate is the complement of unite
mtcars %>%
  unite(vs_am, vs, am) %>%
  separate(vs_am, c("vs", "am"))

Run the code above in your browser using DataLab