Re: [R] Avoiding another loop

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [R] Avoiding another loop
From: Prof Brian D Ripley (ripley@stats.ox.ac.uk)
Date: Tue 30 Jan 2001 - 04:16:06 EST


Message-ID: <Pine.GSO.4.31.0101291811440.9860-100000@auk.stats>

On Mon, 29 Jan 2001, Michael Roberts wrote:

> Hello,
>
> Is there a fancy way I can use a function (like apply)
> to avoid a the follwoing loop, or otherwise make this more
> efficient? It fills a 3-d array, one matrix at a time.
> "nsize" is big, and efficiency is important.
>
> for (i in 1:nsize) simy[,,i] <- myfunction(p1,p2, ...)
>

You will need to tell us a lot more. At present it appears that you are
doing the same calculation nsize times, which is of course easy to avoid.

Avoiding loops in R is by no mean always useful or effective. There are
myths about that go back to long-forgotten versions of S, in which for
loops were very much to be avoided. Up to a point *vectorization* is
worthwhile, the point being where handling large vectors becones expensive.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Thu 01 Feb 2001 - 16:14:44 EST