You can do: ## R < 3.1
dt[, list(x=list(x), y=list(y)), by=list(grp = x %% 3)] ## >= 3.1 (for now, until bug #5585<https://r-forge.r-project.org/tracker/index.php?func=detail&aid=5585&group_id=240&atid=975>is fixed) dt[, list(x=list(I(x)), y=list(I(y))), by=list(grp = x %% 3)] On Sun, Apr 27, 2014 at 1:47 PM, 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
