<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/why-r-for-data-science-and-not-python/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.ephorie.de/why-r-for-data-science-and-not-python"> R-Bloggers – Learning Machines</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div data-backend-url="http://blog.ephorie.de/wp-content/plugins/shariff-sharing/backend/index.php" data-temp="/tmp" data-orientation="horizontal" data-lang="en" data-theme="color" data-service="gftlr" data-services="[&quot;googleplus&quot;,&quot;facebook&quot;,&quot;twitter&quot;,&quot;linkedin&quot;,&quot;reddit&quot;,&quot;whatsapp&quot;,&quot;mail&quot;,&quot;info&quot;]" data-title="Why R for data science – and not Python?" data-info-url="http://ct.de/-2467514" data-ttl="60" data-url="http://blog.ephorie.de/why-r-for-data-science-and-not-python" data-image=""></div>
<p>There are literally hundreds of programming languages out there, e.g. the whole alphabet of one letter programming languages is taken. In the area of data science there are two big contenders: R and Python. Now why is this blog about R and not Python?</p>
<p>I have to make a confession: I really wanted to like Python. I dug deep into the language and some of its extensions. Yet, it never really worked for me. I think one of the problems is that Python tries to be everybody’s darling. It can do everything… and its opposite. No, really, it is a great language to learn programming but I think it has some really serious flaws. I list some of them here:</p>
<li>It starts with which version to use! The current version has release number 3 but there is still a lot of code based on the former version number 2. The problem is that there is no backward compatibility. Even the syntax of the <code>print</code> command got changed!</li>
<li>The next thing is which distribution to chose! What seems like a joke to R users is a sad reality for Python users: there are all kinds of different distributions out there. The most well known for data science is Anaconda: <a rel="nofollow" href="https://www.anaconda.com/" target="_blank">https://www.anaconda.com/</a>. One of the reasons for this is that the whole package system in Python is a mess. To just give you a taste, have a look at the official documentation: <a rel="nofollow" href="https://packaging.python.org/tutorials/installing-packages/" target="_blank">https://packaging.python.org/tutorials/installing-packages/</a> – seven (!) pages for what is basically one command in R: <code>install.packages()</code> (I know, this is not entirely fair, but you get the idea).</li>
<li>There are several GUIs out there and admittedly it is also a matter of taste which one to use but in my opinion when it comes to data scientific tasks – where you need a combination of on-line work and scripts – there is no better GUI than RStudio from Microsoft (there is now Rodeo, free download here: <a rel="nofollow" href="https://www.yhat.com/products/rodeo" target="_blank">https://www.yhat.com/products/rodeo</a>, but I don’t know how mature it is).</li>
<li>There is no general rule when to use a function and when to use a method on an object. The reason for this problem is what I stated above: Python wants to be everybody’s darling and tries to achieve everything at the same time. That it is not only me can be seen in this illuminating discussion where people scramble to find criteria when to use which: <a rel="nofollow" href="https://stackoverflow.com/questions/8108688/in-python-when-should-i-use-a-function-instead-of-a-method" target="_blank">https://stackoverflow.com/questions/8108688/in-python-when-should-i-use-a-function-instead-of-a-method</a>. A concrete example can be found here, where it is explained why the function <code>any(df2 == 1)</code> gives the wrong result and you have to use e.g. the method <code>(df2 == 1).any()</code>. Very confusing and error prone.</li>
<li>More sophisticated data science data structures are not part of the core language. For example you need the NumPy package for vectors and the pandas package for data.frames. That in itself is not the problem but the inconsistencies that this brings. To give you just one example: whereas vectorized code is supported by NumPy and pandas it is not supported in base Python and you have to use good old loops instead.</li>
<li>Both Python and R are not the fastest of languages but the integration with one of the fastest, namely C++, is so much better in R (via Rcpp by Dirk Eddelbuettel) than in Python that it can by now be considered a standard approach. All R data structures are supported by corresponding C++ classes and there is a generic way to write ultra fast C++ functions that can be called like regular R functions:</li>
<pre>
library(Rcpp)

bmi_R &lt;- function(weight, height) {
  weight / (height * height)
}
bmi_R(80, 1.85) # body mass index of person with 80 kg and 185 cm
## [1] 23.37473

cppFunction(&quot;
  float bmi_cpp(float weight, float height) {
    return weight / (height * height);
  }
&quot;)
bmi_cpp(80, 1.85) # same with cpp function
## [1] 23.37473
</pre>
<p>One of the main reasons for using Python in the data science arena is shrinking by the day: Neural Networks. The main frameworks like Tensorflow and APIs like Keras used to be controlled by Python but there are now excellent wrappers available for R too (<a rel="nofollow" href="https://tensorflow.rstudio.com/" target="_blank">https://tensorflow.rstudio.com/</a> and <a rel="nofollow" href="https://keras.rstudio.com/" target="_blank">https://keras.rstudio.com/</a>).</p>
<p>All in all I think that R is really the best choice for most data science applications. The learning curve may be a little bit steeper at the beginning but when you get to more sophisticated concepts it becomes easier to use than Python. </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.ephorie.de/why-r-for-data-science-and-not-python"> R-Bloggers – Learning Machines</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/nI_wvW1lwlM" height="1"></a></div>