I think you should use a single data.table; it's much more straightforward in that case:
qq <- data.table(runif(18),id=rep(1:2,each=9)) qq[,freq:=.N,by=.(id,seq(nrow(qq))%/%5)] This differs from your code, but I doubt that you really meant to do by=V1, since V1 is continuous and therefore is almost guaranteed to have groups of size one. --Frank On Mon, Jul 20, 2015 at 11:39 AM, Sebastian Fischmeister < [email protected]> wrote: > Hi, > > I'm trying to split a data.table and then update the individual > splits. Does anyone have an idea, why this doesn't work? > > Thanks, > Sebastian > > > > library(data.table) > > ## this doesn't work > q <- list(data.table(runif(9)),data.table(runif(9))) > lapply( q, function(xx) { qq <- split(xx, 1:nrow(xx) %/% 5) > lapply(qq, function(xx) { xx[, freq:=.N, > by="V1"] }) > }) > > ## this doesn't work either although freq now exists > q <- list(data.table(runif(9)),data.table(runif(9))) > lapply(q, function(xx) xx[,freq:=-1] ) > lapply( q, function(xx) { qq <- split(xx, 1:nrow(xx) %/% 5) > lapply(qq, function(xx) { xx[, freq:=.N, > by="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
