Skip to content
Prev 170673 / 398506 Next

Alternate to for-loop

Patrick Burns wrote:
a naive benchmark:

f.rep = function(n, m) replicate(n, rnorm(m))
f.pat = function(n, m) colMeans(array(rnorm(n*m), c(n, m)))

system.time(f.pat(1000, 1000))
system.time(f.rep(1000, 1000))

makes me believe that there is no significant difference in efficiency
between the 'professionally-looking' replicate-based solution and the
'as fast as possible' pat's solution.

vQ