try this: > dt = data.table (x=10:14, y=20:24) > # create new 'x' column > dt[, newX := x] > dt[ + , list(x = toString(x) + , y = toString(y) + ) + , key = newX %% 3 + ] newX x y 1: 0 12 22 2: 1 10, 13 20, 23 3: 2 11, 14 21, 24
Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Sun, Apr 27, 2014 at 7:47 AM, Dan Muresan <[email protected]> wrote: > 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")? > _______________________________________________ > datatable-help mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help >
_______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
