5 ms·
Python has better and better support for R with Rpy2 and R like data frames with Pandas, which is helping me take advantage of the incredibly useful analysis li
by chuckcode 12y ago
Python has better and better support for R with Rpy2 and R like data frames with Pandas, which is helping me take advantage of the incredibly useful analysis libraries in R.
Also note that loops are slow enough that it is really worth learning the *apply() functions in R to avoid iterating over collections. For a relatively in depth explanation check out Hadley Wickham's book http://adv-r.had.co.nz/Functionals.html http://adv-r.had.co.nz/Functionals.html
- mbq 12y ago*apply functions are loops underneath -- they only look better and save you time possibly wasted on growing some dynamically sized output structure. The way of solving slow loop in R is to find package which implements it in C/Fortran (or write your own in case there is none).
- platz 12y agoI believe there is also the Rcpp package which lets you write inline compiled c++
- craigching 12y ago> * apply functions are loops underneath Yes, but aren't they native loops underneath? I've seen it said both ways, that * apply is faster than R loops and that *apply isn't faster than R loops. Would be nice if someone could definitively answer the question and back it up with some stats! :) EDIT: Thanks chuckcode, sibling post to this, I stand corrected :)
- chuckcode 12y agoIt'a actually a little complicated but if you're interested in the details check out this stack overflow thread [1]. High level summary is that lapply() and functions built on top of it do some work in native C and so are generally faster but not all of the *apply() functions are faster. [1] http://stackoverflow.com/questions/2275896/is-rs-apply-family-more-than-syntactic-sugar http://stackoverflow.com/questions/2275896/is-rs-apply-famil...
- mbq 12y agoThe problem here is not the for-loop itself but the time used by the R runtime on executing the mapped function multiplied by the number of iterations (this is BTW the main source of advantage for dynamic and GCed but JITed languages like JS or Julia).
- wch 12y agoIt's a common misconception that for loops in R are slow. They're actually fast (around 20 million iterations per second on my computer). What can be slow is modifying data structures in particular ways using a loop. See http://rpubs.com/wch/46581 http://rpubs.com/wch/46581