[R] alternative to rbind for data.table

Christof Kluß ckluss at email.uni-kiel.de
Sat Jul 21 13:21:58 CEST 2012


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



More information about the R-help mailing list