[R] Difference between loops and vectorization

Dieter Menne dieter.menne at menne-biomed.de
Wed Dec 1 09:09:12 CET 2010



Santosh Srinivas wrote:
> 
> A fundamental question ...I'm trying to understand the differences between
> loop and vectorization ... I understand that it should be a natural choice
> to use apply / adply when it is needed to perform the
> same function across all rows of a data frame. Any pointers on why this is
> so? Unable to find the right reading place on the WWW which explains the
> concept.
> 

Strange. "loop vectorization" gives a few hundred of hits, that tell you
that loops are not as bad in R (compared to S) in many cases. "apply" is
probably the least important vectorization method in R, but I admit that
some texts make us believe that it is the point where you show your
R-talents.

"adply" is different: it is a rather complex function from package plyr by
Hadley Wickham. This package provides some elegant orthogonal functions
under a unified concept. I found it appealing at the first look, but I am
less frequently using it nowadays because it can be terribly slow.

Try the chapter in 

http://www.burns-stat.com/pages/Tutor/R_inferno.pdf

Dieter

-- 
View this message in context: http://r.789695.n4.nabble.com/Difference-between-loops-and-vectorization-tp3066585p3066788.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list