Skip to content
Prev 170740 / 398506 Next

Alternate to for-loop

Stefan Evert wrote:
what you're benchmarking here is a lump of vector allocation and the
actual summing.  assuming that you already have generated and stored the
values to be summed, the runtime differs a bit:

system.time(sum(as.numeric(1:10^8)))

system.time({ x = 1:10^8 })
system.time({ y = as.numeric(x) })
system.time(sum(y))

though again, it's a factor below one order of magnitude.

vQ