Petr Pikal wrote:
> 
> Hi
> 
> [EMAIL PROTECTED] napsal dne 03.09.2008 16:39:07:
> ....
>> In many cases I've noticed that using apply, sapply etc can help 
>> speeding up processes, but in this case I don't see how I could do so.
>> 
>> a <- runif(10000000,0.5,1.6)
>> C <- 2
>> M <- 10000000
>> system.time( for (i in 1:(M-1)) {C <- C* c(a[i],a[i+1])} )
> 
> Maybe simple math? You want last two members of 2*cumprod(a).
> 
> So
> 
>> system.time(2*cumprod(a)[9999999:10000000])
>    user  system elapsed 
>    1.97    0.04    2.00 
>>
> 
> shall be a little bit quicker then for cycle. But it is valid only for the 
> above calculation.
> 

I think

2*c(cumprod(a)[M-1],cumprod(a[-1])[M-1])

is the answer.

Berend
-- 
View this message in context: 
http://www.nabble.com/optimizing-speed-of-calculation--%28recursive-product%29-tp19290678p19293353.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to