[datatable-help] What's the trick to paste several columns together in one
Eduard Antonyan
eduard.antonyan at gmail.com
Thu Jul 23 21:34:47 CEST 2015
Agreed, SO is much more suited for this and previous questions.
On Thu, Jul 23, 2015 at 2:19 PM, Frank Erickson <fperickson at wisc.edu> wrote:
> 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 <statquant at outlook.com> 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
>> datatable-help at lists.r-forge.r-project.org
>>
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>>
>
>
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150723/aa5bf7a2/attachment.html>
More information about the datatable-help
mailing list