The following scheme may be helpful
indices <- 1:nrow(newdata)
groups <- split(indices, newdata$V7)
lapply(groups, function(idx) {
subdata <- data[idx,]
# some operations on subdata...
})
It prevents R for creating multiple sub-data.frames
at once, and thus may reduce the memory usage. You may also try calling gc(TRUE)
to force garbage collection between each iteration of lapply
.
However, I'm conscious that this is not a highly elegant solution. :)