Skip to content
Prev 180304 / 398502 Next

Simulation

Dimitris Rizopoulos wrote:
sure;  you could also replace 'matrix' with 'as.matrix' in the original
solution, which also gives some speedup:

n=100; m=100
benchmark(replications=1000, columns=c('test', 'elapsed'), order=NULL,
    list={ l=list(); for (i in 1:n) l[[i]] = rnorm(m) },
    liist={ l=vector('list', n); for (i in 1:n) l[[i]] = rnorm(m) },
    matrix=matrix(rnorm(n*m), n, m),
    matrix2 = {mat <- rnorm(n*m); dim(mat) <- c(n, m); mat},
    as.matrix=as.matrix(rnorm(n*m), n, m),
    replicate=replicate(m, rnorm(n))
)

# 3    matrix   0.173
# 4   matrix2   0.162
# 5 as.matrix   0.169

vQ