Skip to contents

Unites multiple columns into one character column.

Usage

unite(data, new, old, sep = "_", remove = TRUE)

Arguments

data

A data frame.

new

A string for the new column name.

old

A character vector of column names to unite.

sep

A string for the separator between values.

remove

TRUE or FALSE. If TRUE, old columns will be removed.

Value

data.frame

Details

The new column will be inserted into the data frame where the first old column is located.

See also

Examples

#----------------------------------------------------------------------------
# unite() examples.
#----------------------------------------------------------------------------
library(bkdat)

df <- data.frame(
  a = letters[1:3],
  b = letters[4:6],
  c = letters[7:9],
  stringsAsFactors = FALSE
)
unite(df, "new_col", c("a", "b"), sep = "_", remove = TRUE)
#>   new_col c
#> 1     a_d g
#> 2     b_e h
#> 3     c_f i
unite(df, "new_col", c("c", "b"), sep = "-", remove = FALSE)
#>   a b new_col c
#> 1 a d     g-d g
#> 2 b e     h-e h
#> 3 c f     i-f i