[datatable-help] Unexpected behaviour using fast grouping

Tom Harrop thomas.harrop at ird.fr
Mon Aug 4 13:40:20 CEST 2014


Hello,

I'm trying to group a data.table that has duplicate keys, aggregating 
the values in another column by the value of the key.

There is a question and answer on the same topic on StackOverflow 
(http://stackoverflow.com/a/17033371/3017012), but when I follow the 
accepted answer I get different results:

 > library(data.table)
data.table 1.9.2  For help type: help("data.table")
 > dt = data.table(user_id = c(1,2,2,3), advertiser_id = c(1:4))
 > dt[,list(list(advertiser_id)), by = user_id]
    user_id  V1
1:       1 4,3
2:       2 4,3
3:       3 4,3

Where I expect:

    user_id  V1
1:       1   1
2:       2 2,3
3:       3   4

I can get the expected results (as above) using:

 > dt[,paste(advertiser_id, collapse = ","), by = user_id]

Have I missed something? I'm on R 3.1.1 in case the behaviour has 
changed recently.

Many thanks,

Tom


More information about the datatable-help mailing list