Skip to content
Prev 165929 / 398502 Next

R badly lags matlab on performance?

Ajay Shah wrote:
this list has a tradition of encouraging users to use apply&relatives
instead of for loops (and to use vectorised code instead of both).

compare the following for n = 10^6 and n = 10^7:

x = 1:n
system.time({for (i in 1:n) x[i] = x[i] + 1})

x = 1:n
system.time({x = sapply(x, `+`, 1)})


vQ