Skip to content
Prev 170684 / 398506 Next

Alternate to for-loop

Wacek Kusnierczyk wrote:
I think Wacek is largely correct.  First off, a correction:
the dimensions on the array if 'f.pat' should be c(m, n)
rather than c(n, m).

What I'm seeing on my machine is that the array trick seems
always to be a bit faster, but only substantially faster if 'm'
(that is, the number being summed) is smallish.

That makes sense: loops are "slow" because of the overhead
of doing the calling.  When each call takes a lot of time,
the overhead becomes insignificant.


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of "The R Inferno" and "A Guide for the Unwilling S User")