You need to preallocate. [See the R Inferno]
n <- 1
dt <- as.data.table(matrix(0, nrow = n, ncol = 5))
for(i in seq_len(n)){
dt[i, ] <- ### Whatever
}
Note that this *might* be somewhat trickier with data.tables and their
fancy indexing. It might be easier to simply assign into the matrix
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:1)) {
# algorithm that generates a list with dif
2 matches
Mail list logo