Bert Gunter <gunter.berton <at> gene.com> writes: > > FWIW: > > Good advice below! -- after all, the first rule of optimizing code is: > Don't! > > For the record (yet again), the apply() family of functions (and their > packaged derivatives, of course) are "merely" vary carefully written for() > loops: their main advantage is in code readability, not in efficiency gains, > which may well be small or nonexistent. True efficiency gains require > "vectorization", which essentially moves the for() loops from interpreted > code to (underlying) C code (on the underlying data structures): e.g. > compare rowMeans() [vectorized] with ave() or apply(..,1,mean). [...]
The apply-functions do bring speed-advantages. This is not only what I read about it, I have used the apply-functions and really got results faster. The reason is simple: an apply-function does make in C, what otherwise would be done on the level of R with for-loops. Ciao, Oliver ______________________________________________ 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.