r/statistics • • Apr 19 '18

Software Is R better than Python at anything? I started learning R half a year ago and I wonder if I should switch.

I had an R class and enjoyed the tool quite a bit which is why I dug my teeth a bit deeper into it, furthering my knowledge past the class's requirements. I've done some research on data science and apparently Python seems to be growing faster in the industry and in academia alike. I wonder if I should stop sinking any more time into R and just learn Python instead? Is there a proper GGplot alternative in Python? The entire Tidyverse package is quite useful really. Does Python match that? Will my R knowledge help me pick up Python faster?

Does it make sense to keep up with both?

Thanks in advance!

EDIT: Thanks everyone! I will stick with R because I really enjoy it and y'all made a great case as to why it's worthwhile. I'll dig into Python down the line.

140 Upvotes

153 comments sorted by

View all comments

Show parent comment

5

u/bjorneylol Apr 19 '18

I commented above, but I believe pandas is still much faster provided you downcast string arrays to indexed categories (which R does by default).

Pandas benchmarks 2-10x faster for me

2

u/akcom Apr 20 '18

What sort of operations are you performing? I found pandas to be substantially slower on groupby(), calculating aggregates, and most importantly join/merge

1

u/bjorneylol Apr 20 '18

I revised my numbers, my R code was apparently not optimal (https://www.reddit.com/r/statistics/comments/8de54s/is_r_better_than_python_at_anything_i_started/dxnhr80/)

From what I'm seeing now they are basically equivalent. I think there are going to be edge cases where one outperforms the other, but a lot of the speed will come down to things I'm not willing to test (I'm using the windows binaries, I'm sure if I compiled everything from source to take advantage of hardware optimizations the results may be drastically different)

I haven't tested join/merge but I would assume they are similar if you perform them in the optimal way (along an integer axis is pandas) - i'm not sure how the pandas categorical types handle manipulation (I think they convert back to string) so I wouldn't be surprised if R outperforms in that regard.

1

u/backgammon_no Apr 20 '18

Is this like R's factors?

My data is usually unique, not factorizable.

2

u/bjorneylol Apr 20 '18

Yeah, pandas categorical type is similar to R's factor (integers under the hood, but displays the associated string data).

If its unique data there is no point in using pandas categories, I'm not sure if R converts to string as well? In either case I assume you aren't doing a ton of subsetting/grouping/joining on unique string columns