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?
For completeness' sake, an official answer:
If you use paste(y,collapse=",")
instead, it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With