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

Arunkumar Srinivasan aragorn168b at gmail.com
Thu Jun 25 21:53:36 CEST 2015


To add to Frank’s reply, I think `dt[, V3 := .(list(V1)), by=V2]` doesn’t work with `1.9.4`, but has been fixed in 1.9.5.
The first list is for the syntax - (cols) := list(values). Cases like `DT[, A := 1:5]` and is internally wrapped by `list()` for convenience, as they are very common use cases.
-- 
Arun

On 25 Jun 2015 at 21:51:09, Frank Erickson (fperickson at wisc.edu) wrote:

Oh, sorry, didn't notice you were making a new column, in that case: dt[,V3:=list(list(V1)),by=V2]


On Thu, Jun 25, 2015 at 3:48 PM, Frank Erickson <fperickson at wisc.edu> wrote:
Hi,

I think you want

dt[,.(list(V1)),by=V2]
#    V2  V1
# 1:  a 1,4
# 2:  b 2,3


Using the .() notation makes it easier to keep track of what columns are being made, I find.

--Frank

On Thu, Jun 25, 2015 at 3:46 PM, Nicolas Paris <niparisco at gmail.com> wrote:
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



_______________________________________________
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/20150625/c6f646cb/attachment-0001.html>


More information about the datatable-help mailing list