combine two columns in r code example

Example 1: combine columns in r

df.1 <- data.frame("Name" = c("Jill","Jack","John"))
df.2 <- data.frame("Age" = c(42,16,63))
df.comb <- cbind(df.1,df.2)

Example 2: r combine strings

> paste("Hello", "world", sep=" ")
[1] "Hello world"

Example 3: how to combine all columns into one column in r

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

Example 4: combine ro columns in r

df$x <- paste(df$n,df$s)
 df
#   n  s     b    x
# 1 2 aa  TRUE 2 aa
# 2 3 bb FALSE 3 bb
# 3 5 cc  TRUE 5 cc

Tags:

R Example