[R] A question on Programming

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Nov 11 15:35:25 CET 2011


Hi,

On Fri, Nov 11, 2011 at 7:26 AM, Oliver <oliver at first.in-berlin.de> wrote:
> Christofer Bogaso <bogaso.christofer <at> gmail.com> writes:
> [...]
>> Here my question is, is there any speed reduction if I put them within a
>> function (I think there may be some speed reduction at least within
>> for-loop, because that loop needs to call that function many times),
>> relative to if I used that group of codes as-it-is in many places?
> [...]
>
>
> You did not asked for it, you may know it, or may not know it:
> if you use apply functions and other vector oriented functions,
> this can bring you a huge speedup, compared to a for-loop.

I don't think this is exactly true.

I believe the majority *apply functions are really more-or-less just
sugar that boil down to having a for loop buried within them.

This is just to say that I'm not sure how much of a speedup anybody
should expect switching from a `for` loop to `*apply` function
(assuming you aren't growing an array w/in each iteration of a for
loop, for example), but if you can replace the for/*apply loop with a
few lines of vectorized functions, then yeah -- you can expect big
gains.

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the R-help mailing list