I wanna merge the following columns
p t
1 2
3 4
2 5
output:
m
1,2
3,4
2,5
We can use paste
with(df1, paste(p, t, sep=","))
Or with unite
library(dplyr)
unite(df1, m, p, t, sep=",")
Akrun's solution is excellent but I also like to do it with data.table
if you're are using this package.
library(data.table)
dt <- as.data.table(dt)
dt <- dt[, m := paste0(p, ",", t)][,c(3)]
Output :
m
1: 1,2
2: 3,4
3: 2,5