<div dir="ltr">I think you should use a single data.table; it's much more straightforward in that case:<div><br></div><div><div>qq <- data.table(runif(18),id=rep(1:2,each=9))</div><div>qq[,freq:=.N,by=.(id,seq(nrow(qq))%/%5)]</div><div><br></div><div>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.</div><div><br></div><div>--Frank</div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 20, 2015 at 11:39 AM, Sebastian Fischmeister <span dir="ltr"><<a href="mailto:sfischme@uwaterloo.ca" target="_blank">sfischme@uwaterloo.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm trying to split a data.table and then update the individual<br>
splits. Does anyone have an idea, why this doesn't work?<br>
<br>
Thanks,<br>
  Sebastian<br>
<br>
<br>
<br>
library(data.table)<br>
<br>
## this doesn't work<br>
q <- list(data.table(runif(9)),data.table(runif(9)))<br>
lapply( q, function(xx) { qq <- split(xx, 1:nrow(xx) %/% 5)<br>
                          lapply(qq, function(xx) { xx[, freq:=.N, by="V1"] })<br>
                      })<br>
<br>
## this doesn't work either although freq now exists<br>
q <- list(data.table(runif(9)),data.table(runif(9)))<br>
lapply(q, function(xx) xx[,freq:=-1] )<br>
lapply( q, function(xx) { qq <- split(xx, 1:nrow(xx) %/% 5)<br>
                          lapply(qq, function(xx) { xx[, freq:=.N, by="V1"] })<br>
                      })<br>
<br>
<br>
<br>
_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
</blockquote></div><br></div>