[datatable-help] [data.table] Aggregate as vector

Nicolas Paris niparisco at gmail.com
Thu Jun 25 21:46:40 CEST 2015


Hi,

Here an example what I want to get :

> dt <- data.table(c(1,2,3,4),c("a","b","b","a"))
> dt
   V1 V2
1:  1  a
2:  2  b
3:  3  b
4:  4  a

What I want to get is a V3 column, containing an aggregated vector :
> dt
   V1 V2 V3
1:  1  a   c(1,4)
2:  2  b   c(2,3)

That does not work :

dt[,V3 := as.list(c(V1)),by=V2]

Is there a way to do so ?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20150625/a06c283b/attachment.html>


More information about the datatable-help mailing list