beginneR beginneR - 2 months ago 23
R Question

paste two data.table columns

dt <- data.table(L=1:5,A=letters[7:11],B=letters[12:16])
L A B
1: 1 g l
2: 2 h m
3: 3 i n
4: 4 j o
5: 5 k p


Now I want to paste columns "A" and "B" to get a new one, let's call it "new":

dt2
L A B new
1: 1 g l gl
2: 2 h m hm
3: 3 i n in
4: 4 j o jo
5: 5 k p kp

Answer

Arun's comment answered this question:

dt[,new:=paste0(A,B)]