paste, by and data.table in r
data.table, r
Solution
For completeness' sake, an official answer:
If you use `paste(y,collapse=",")` instead, it should work.
Problem
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?