I think you want DT[,(newName):=do.call(paste,c(list(sep="_"),.SD)),.SDcols=colNames]
This is probably the sort of thing that would come naturally after studying all the vignettes and such on the site: https://github.com/Rdatatable/data.table/wiki/Getting-started Dunno that you want to be sending so much stuff to everyone on a mailing list. Your call, though. --Frank On Thu, Jul 23, 2015 at 3:13 PM, statquant3 <[email protected]> wrote: > R) data.table(x=letters[1:5],y=rnorm(5),z=LETTERS[1:5]) > x y z > 1: a 0.5551301186 A > 2: b 0.1092535710 B > 3: c -2.4319115661 C > 4: d 1.6915588561 D > 5: e -1.5163715976 E > > colNames = c('y','z') > newName = 't' > > How do I add a column 't' such that t:=paste(y,x,sep='_') > > x y z t > 1: a 0.5551301186 A 0.5551301186_A > 2: b 0.1092535710 B 0.1092535710_B > 3: c -2.4319115661 C ... > 4: d 1.6915588561 D ... > 5: e -1.5163715976 E ... > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/What-s-the-trick-to-paste-several-columns-together-in-one-tp4710266.html > Sent from the datatable-help mailing list archive at Nabble.com. > _______________________________________________ > datatable-help mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help >
_______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
