3 ms·
I don't know how Python handles it, but R uses vector operations for almost every function, meaning that for large data sets (10000+), the efficiency of data ma
by minimaxir 14y ago
I don't know how Python handles it, but R uses vector operations for almost every function, meaning that for large data sets (10000+), the efficiency of data manipulation in R is always O(1), and may otherwise be O(n) in Python.
I have a function in R that given a list of keywords, for each word (~100 keywords), it checks a data frame that stores a list of keywords (~5000 lists of keywords, ~10 keywords/list) to see which keywords matches the keywords in each row of the data frame.
Efficiency using straight for loops would be O(mno) and could take awhile. But in R, all those operations are vectors, and it takes less than a second.
- teraflop 14y ago"Vector operations" cannot magically turn an O(n) operation into an O(1) operation, no matter what language you're using.
- minimaxir 14y agoFair enough. You're right, O(1) might not be the most accurate efficiency for what I'm describing.
- pyoung 14y agoI imagine your mileage may vary depending on the functions and operations that you are performing. I did a simple test of python vs R and python was the overwhelmingly faster. I believe both languages are primarily written in C, and as such, the speed of your program will depend on the 'efficiency' of the underlying code for the functions you are using.
- cschmidt 14y agoR is horrifically slow on loops. If you can vectorize the operation, then it will be reasonably fast. If you have to use an explicit loop, then python will be faster. My previous company had a saying that "R is fast if your write it in C". If you have many nested loops, you'll probably need to write a C extension.