r/statistics • u/outrageously_smart • 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.
100
u/marrone12 Apr 19 '18
Honestly pandas has a terribly obtuse syntax but python is much better programming language for everything besides statistical analysis. I mostly code in python out of necessity but data analysis itself is much better in R.
22
u/edimaudo Apr 19 '18
You can use either R or python for data science. The only difference would be if you want to build a data pipeline or production level code. This is where python would outshine R. If you know how to program then learning another language would be trivial.
158
u/shaggorama Apr 19 '18 edited Apr 19 '18
I think one of the main differences people overlook is that R's analytics libraries often have a single owner who is usually a statistical researcher -- which is usually reflectrd by the library being associated with a JStatSoft publication and inclusion of citations for the methods used in the documentation and code -- whereas the main analysis libraries for python (scikit-learn) are authored by the open source community, don't have citations for their methods, and may even be authored by people who don't really know what they're doing.
Case in point, sklearn doesn't have a bootstrap crossvalidator despite the bootstrap being one of the most important statistical tools of the last two decades. In fact, they used to, but it was removed. Weird right? Well, poking around the "why" is extremely telling, and a bit concerning. Here are some choice excerpts from an email thread sparked by someone asking why they were getting a deprecation warning when they used sklearn's bootstrap:
I don't know about you guys, but personally I found this exchange extremely concerning. How many other procedures in the library are "just made up" by some contributor? Another thing you're not seeing is how much of the preceding discussion was users trying to justify the removal of the method because they just don't like The Bootstrap or think it's not in wide use. My main issue here is obviously that a function was implemented which simply didn't do the action described by its name, but I'm also not a fan of the community trying to control how their users perform their analyses.
To summarize: the analytical stacks for both R and python are generally open source, but python has a much larger contributor community and encourages users to participate whereas R libraries are generally authored by a much smaller cabal, often only one person. Your faith in an R library is often attached to your trust in an individual researcher, who has released that library as an implementation of an article they published and cited in the library. This is often not the case with python. My issue is primarily with scikit-learn, but it's a central enough library that I think it's reasonable to frame my concerns as issues with python's analytic stack in general.
That said, I mainly use python these days. But I dig really, really deep into the code of pretty much any analytical tool I'm using to make sure it's doing what I think it is and often find myself reimplementing things for my own use (e.g. just the other day I had to reimplement
sklearn.metrics.precision_recall_curve). Stumbling across the exchange above made me paranoid, and frankly the more experience I have with sklearn the less I trust it.EDIT: Oh man, I thought of another great example. I bet you had no idea that sklearn.linear_model.LogisticRegression is L2 penalized by default. "But if that's the case, why didn't they make this explicit by calling it RidgeClassifier instead?" Maybe because sklearn has a Ridge object already, but it exclusively performs regression? Who knows (also... why L2 instead of L1? Yeesh). Anyway, if you want to just do unpenalized logistic regression, you have to set the
Cargument to an arbitrarily high value, which can cause problems. Is this discussed in the documentation? Nope, not at all. Just on stackoverflow and github. Is this opaque and unnecessarily convoluted for such a basic and crucial technique? Yup.And speaking of the sklearn community trying to control how its users perform analyses, here's a contributor trying to justify LR's default penalization by condescendingly asking them to explain why they would want to do an unpenalized logistic regression at all.
59
u/gsmafra Apr 19 '18
From someone who was doing Python for 3 years and recently started with R (some months):
13
u/coffeecoffeecoffeee Apr 19 '18
Learn both. R’s tidyverse packages are amazing and by far the most intuitive approach to data manipulation that I’ve ever worked with. R’s visualization capabilities via ggplot2 also blow Python’s out of the water, as do its inference packages (inference, not predictive).
Python easily wins the “better base language, string manipulation, and machine learning” battle, but R’s packages make so many difficult procedures into one liners that I almost always use R over Python.
42
u/mdz76 Apr 19 '18
R has more advanced statistics packages for high-level modeling.
10
u/DS11012017 Apr 19 '18
My general thought process:
If you are producing inference and analytics type work most of the time I would prefer R.
If you have to move your scripts to a server, for data pipelines, near time prediction ect. I definitely prefer python.
9
u/Jerome_Eugene_Morrow Apr 19 '18
There's really no reason not to use both. I feel like Python is the workflow standard for data scraping and cleaning, and R is the best tool for actual analysis. As others have pointed out, Python has much better flexibility and speed in general programming applications, but R has the best libraries for statistical analysis. You can definitely make a case for Python being the better platform for machine learning, due to its integration with platforms like TensorFlow, but for more general statistical analysis R blows it away due to the sheer size and quality of CRAN.
Knowledge of any programming language will help you pick up your next one. A friend once told me that the best skill you can have as a programmer is knowing how to learn a new tool, programming languages included, so by all means try and learn the skill of picking up new languages and taking them for a test drive. One will probably end up being your go-to as defined by your day-to-day work, but general programming abilities and your ability to read documentation and code will keep increasing across languages.
19
u/midianite_rambler Apr 19 '18
R is a terrible programming language, but basic statistical stuff is very simple, with literally bazillions of useful, interesting packages. Python is a stronger programming language, but somewhat clumsier for basic statistical stuff, and a more limited range of packages.
My advice is learn and use both. Sometimes one's a better fit, sometimes the other.
6
u/rz2000 Apr 19 '18
Realistically, you try to be comfortable with both.
Exploratory data analysis especially seems far more intuitive in R to me, and R gives you easier access to newer or more advanced statistics. Yet, in spite of how well it works for statistics Python has better access to many platforms, including those that nominally support R, and parts of your process of collecting and cleaning data are likely to be terrible in R but simple with Python.
5
u/TheDrownedKraken Apr 19 '18
If I'm doing some exploratory analysis or modelling, most often, I'll go to R. If I'm building something to be used or with a larger scope than just analysis, I'll go to Python.
4
u/[deleted] Apr 19 '18 edited Apr 19 '18
There are performance and syntax arguments for both that others have made here more eloquently than I could. But an important thing to note that I haven't seen in this thread is the composition of the two languages' communities.
R's user community has a greater fraction of statisticians and non-computational researchers (e.g. biologists). This is just my impression, but I imagine most people would agree. So, if you have questions about specific statistical methods or domain-specific analysis, you'll probably get more answers on stackoverflow/reddit/wherever if you're using R.
7
u/jackmaney Apr 19 '18
3
u/[deleted] Apr 20 '18 edited Apr 20 '18
R have a lot more packages than Python within the statistic domain.
The authors of Element of Statistic Learning, Hastie and Tibshirani made glmnet R package.
It took Python forever for a port that over to Python.
glmnet R version 1 package was publish in 2008-05-14.
Python glmnet was publish in 2016-10-15.
Both author are famous statistician and especially for feature selection. So yeah R is much much better than Python in statistical packages.
Also R was made to do data. Python is a generalize programming langauge.
There are pro and con for both approach. But because R was made to deal with data from the get go, it's built into the language so the syntax will be much better when dealing with data.
You can argue that you don't like R syntax but from a polygot point of view when a programming language bake it in from the get go you don't have to do bandaid or have a separate package. I don't recall Python let you operator overload like C++ so you have to have methods to do operation.
An concrete example is R have the concept of missing data NA.
Python panda uses Null.
From software engineering tips not to do is use Null for stuff. Because everybody throw whatever into Null. Null == Null does this even make sense? Python language isn't aware of missing data as a language, it just have a package Panda which states that Null is missing data. Is null in python really missing data or some error or default that produce Null? Sure python is strong type but the default behavior up to the programmer not the programming language.
I'mma buck the trend and say from experience:
Become an expert in one first and learn enough to get by the other. Don't learn both at the same time.
5
u/halianlian Apr 19 '18
R has RStudio, which is amazing for explorating and messing around with data and transformations. But as python is also an all purpose language, I feel its an intelligent decision to be fluent in both.
4
u/pandemik Apr 19 '18
They're both useful languages. It's valuable to know R and it's valuable to know python.
2
u/[deleted] Apr 19 '18
I'd say R has better plotting capabilities. It's base graphics stuff is already pretty good, and then GGPlot adds a lot. I know there are similar packages in Python, but IMO they're not as immediately intuitive. Also there are some great GIS packages in R, not as sure about Python.
2
u/jaaval Apr 19 '18
For basic data manipulation and statistics R is in my experience a shitton less verbose. And many important features are core part of the language instead of some module.
2
u/agclx Apr 19 '18
As everybody said - python is a much clearer language.
However on point that wasn't mentioned is that a lot of R packages are accompanied by a scientific publication. Which means they went through an academic review process. Also makes it much nicer to argue why you chose a library/method.
2
u/[deleted] Jan 24 '22
Yes, almost all R's statistical packages are better than Python's.
3
u/[deleted] Apr 19 '18
You will get a lot of different answers for this. But in all honesty, likely anything you'll be doing in either language relating to statistics, you can do in the other language. Differences in many programming languages, especially "high level" languages like python and R, are pretty superficial and amount to syntax differences for the same or similar structures.
Both R and python have variables, functions, control structures, libraries, IDEs, ... as I'm sure you know, but just saying the differences get overstated in the beginner stages of learning and development.
One thing, I would say that while python permits you to code in a functional style, R really supports the "functional programming" paradigm. You can do closures, lambdas, etc in python just as much in R but somehow it always feels a lot cleaner and more natural in R, to me. Of course this doesn't matter at all if you have no interest in functional programming.
You won't lose anything by learning both. Maybe one a bit deeply, then the other, so as to not confuse yourself. But you'll never be irreversibly committed to one at the exclusion of the other.
2
u/feelphree Apr 19 '18
I have a good bit of experience with both and happen to prefer Python these days. One point that I don't often see mentioned in these discussions is that many cloud services support Python better than R out of the box.
2
u/jmmcd Apr 19 '18
In R, there's one (usually very good) way to do anything relating to statistics. In Python, there are lots of ways, of varying quality, to do just about anything. Most neural networks stuff is in Python rather than R.
1
u/-TrustyDwarf- Apr 19 '18
depends on who you ask and depends on what your task is. just learn both and use whatever fits the task best.
1
u/gwynbleiddeyr Apr 19 '18
Leaving the libraries and ecosystem (others have already talked about them), R has better metaprogramming (see advanced R) capabilities. This can be a pleasurable experience if you are not just using R but developing in it.
EDIT: If you have some interest in the process of programming, go for both the languages for a while.
1
u/hipstertool Apr 20 '18
thanks for asking. I had been wondering the same.
1
u/spamduck Apr 20 '18
Something that hasn't been mentioned yet, but I think Rcpp is a wonderful for hacking some super fast code into an analysis where you need it. Maybe it isn't as good for deployment code as a fancier cross-language solution? But I like it much more than Cython. I used to be a Python-er and make fun of R, but I'm full time R now (data analysis). Tidyverse/ggplot/Rstudio/Rcpp are amazing.
I'd go back to Python for systems stuff probly, but that's not what I do now.
1
u/[deleted] Sep 23 '18 edited Sep 23 '18
Python is like a pair of pliers, while R is like a torque wrench. Sure, you can turn a bolt with pliers, but if you're working on your car's engine, you'd be a fool to abandon your torque wrench for pliers.
1
u/Programom Oct 07 '22
I don't have nearly the number of problems installing libraries for python into Jupyter notebook programs that I do when trying to do so with RStudio. Markup kind of sucks too.
R seems to be designed to confuse programmers who are used to 0-arrays and standard assignment language (= versus <-). I have yet to be convinced that it has any advantages over Python at all.
Mostly, it's a time suck.
1
u/aditya2063 Nov 17 '21
Python is a general purpose programming language that provides many versatile operations such as application development of websites, desktop, and scientific calculations. It is also an interpreted and open source programming language which increases it’s importance even more in the current technological environment. All this combined makes it no surprise for anyone as to why python is currently one of the fastest growing programming languages.
Python Importance in Data Analytics
We live in an era of digital world where we produce on a daily basis 2.5 quintillion bytes of data which needs to be processed to make better use of it and develop future insights. Processing and analyzing such huge amounts of data can be a very time consuming and costly process. Here python helps by having -
● A stunning ecosystem.
● Many data oriented feature packages.
These features makes the processing of such huge quantity of data much simpler and efficient to do so.
Python Importance in Machine Learning
Machine learning is the process that uses data to make intelligence machines that can be taught to recognize patterns in the data to provide actionable future insights. Here python helps by having -
● Libraries and Frameworks
● Simplicity and consistency
● Platform independence
● Great community base.
Python is currently the most preferable programming language by people across different industries. This is the reason why many data science, machine learning and AI aspirants are joining python online courses on Edu4sure and other such online training organization to achieve their career goals.
0
u/Yay_Yay_3780 Apr 19 '18
I put the same question at a recent gathering of data science people. Many voted for python and common points were
0
u/[deleted] Apr 19 '18
[deleted] — view deleted comment
0
u/[deleted] Apr 19 '18
[deleted] — view deleted comment