[datatable-help] data.table: partition like aggregate (FUN = list)

Dan Muresan danmbox at gmail.com
Sun Apr 27 13:47:01 CEST 2014


How do I achieve the following partitioning effect:

dt = data.table (x=10:14, y=20:24)
aggregate (dt, by = list (dt$x %% 3), FUN = list)

  Group.1      x      y
1       0     12     22
2       1 10, 13 20, 23
3       2 11, 14 21, 24

If I try the following it doesn't work (and I think I know why):

dt [, by = x %% 3, j = list(y)]
   x  y
1: 1 20
2: 1 23
3: 2 21
4: 2 24
5: 0 22

(while with j = max (y) it of course works, generating a "V1" column)

Also, how do I name the result of the j-expression (by default the
resulting column is "V1")?


More information about the datatable-help mailing list