> Two of R's central features as a "data science" language are that many of > its core capabilities are "vectorized" -- can calculate on whole objects > (at the user-visible interpreter level) rather than requiring explicit > loops; and that it can use object indexing in several different modalities, > here logical indexing, for extraction and replacement in whole objects such > as vectors and matrices. Not only does this typically yield simpler, more > readable code (admittedly, a subjective judgment), but it is also typically > much faster, though I grant you that this can often be overrated.
i sort of wanted to circle back to this. i learned FORTRAN IV in 1968 (and the last FORTRAN program i wrote was at least 50 years ago), and i *still* write FORTRAN code, even when writing lisp, or R, or awk scripts. it's *very* hard for me to adapt to other styles. so, for that reason, i think it is very useful to help people understand and adjust to R's vector operations. maybe a way to say it might be "here is how you will get better performance, using R's vector operations..." and, then, "however, if you find it simpler, and the performance acceptable, you could do a 'for' loop like this...". (though, as this is all volunteer effort, one obviously takes what one gets.) but, i do think that helping newer users understand how to write efficient code is important. anyway, just my two cents. cheers, Greg ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.