Hi

I want to add a row to a "data.table" in each round of a for loop.
"rbind" seems to be a inefficient way to implement this.

How would you do this? The "slow" solution:

library(data.table)
Rprof("test.out")
dt <- data.table()

for (i in (1:10000)) {
  # algorithm that generates a list with different values,
  # but same key-names, each round, for example
  l <- list(A=1,B=2,C=3,E=4,F=5)
  dt <- rbind(dt,l) # very slow :(
}

Rprof(NULL)
summaryRprof("test.out")

thx
Christof

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to