Skip to content
Prev 9250 / 398502 Next

Avoiding another loop

Hi Michael,
A loop may be the best way to do this, but of course there are loops and
loops.  Rather than create your simy array explicitly and then assign into
its third extent, you might find it quicker to create simy "on the hoof"
and then reshape it.  For example, something like

simy <- lapply(1:nsize, function(i) myfunction(p1, p2, i))
simy <- array(unlist(simy), c(nx, ny, nsize))

will often turn out to be faster.

Cheers, Jonathan.

Jonathan Rougier                       Science Laboratories
Department of Mathematical Sciences    South Road
University of Durham                   Durham DH1 3LE
tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._