Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paste, by and data.table in r

Tags:

r

data.table

I'm trying to paste strings from a reshaped dataset. I'm using the data.table package as follows:

m<-data.frame(x=rep(c("a","b"),20),y=factor(sample(letters,40,replace=T)))
DT<-data.table(m)
setkey(DT,x)
DT[,paste(y,sep=","),by=x]

However, this only gives a new frame quite identical to the original one except for the variable name. I'd like the output to be two concatenated vectors where the variables are pasted together. How can I do this?

like image 992
Misha Avatar asked Oct 30 '12 13:10

Misha


1 Answers

For completeness' sake, an official answer:

If you use paste(y,collapse=",") instead, it should work.

like image 113
joran Avatar answered Sep 29 '22 13:09

joran