[R] How to eliminate this for loop ?

Bert Gunter gunter.berton at gene.com
Tue Nov 9 17:50:24 CET 2010


Erich:

(Assuming this is correct), this is very nice. However, I just wanted
to point out that if you look at the code for Reduce, you'll find it's
implemented with for loops. So the OP's original version using a for
loop is likely to be faster (just as it's likely to be faster than my
actual recursive version).

Cheers,
Bert

On Mon, Nov 8, 2010 at 4:14 PM, Erich Neuwirth
<erich.neuwirth at univie.ac.at> wrote:
> Reduce(function(x1,x2)b*x1-x2,c,init=1,accum=TRUE)
>
> might be what you are looking for.
> This is not fully tested, so you should test it before
> you want to use it.
>
> ______________________________________________
> R-help at 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.
>



-- 
Bert Gunter
Genentech Nonclinical Biostatistics



More information about the R-help mailing list