[R-sig-hpc] Avoiding looping on vector with stochastic dependency

hadley wickham h.wickham at gmail.com
Sun Dec 28 20:27:40 CET 2008


On Sun, Dec 28, 2008 at 12:48 PM, Guillaume Chapron
<carnivorescience at gmail.com> wrote:
> Thanks for your reply. In fact my code example was simplified from something
> more general
>
> for (i in 2:length(w[,1])) {
>                w[i,] <- foo( w[i-1,] )
>        }
>
> and I was trying to write this without a loop. I will look at the method you
> describe, but  I'm not sure if it can still be applied if foo() is quite
> complex. (sorry for sending this to the wrong list, I thought this one was
> about everything that can make R running faster!)

In general, it is not possible to write out such recurrence relations
explicitly in closed form - see (e.g.)
http://en.wikipedia.org/wiki/Recurrence_relation for more details.

Hadley

-- 
http://had.co.nz/



More information about the R-sig-hpc mailing list