<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/r-vs-python-different-similarities-and-similar-differences/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://gigadom.wordpress.com/2017/05/22/r-vs-python-different-similarities-and-similar-differences/"> R – Giga thoughts …</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>A debate about which language is better suited for Datascience, R or Python, can set off diehard fans of these languages into a tizzy. This post tries to look at some of the different similarities and similar differences between these languages. To a large extent the ease or difficulty in learning R or Python is subjective. I have heard that R has a steeper learning curve than Python and also vice versa. This probably depends on the degree of familiarity with the languuge To a large extent both R an Python do the same thing in just slightly different ways and syntaxes. The ease or the difficulty in the R/Python construct’s largely is in the ‘eyes of the beholder’ nay, programmer’ we could say.  I include my own experience with the languages below.</p>
<div>
<h3>1. R data types</h3>
<p>R has the following data types</p>
<ol>
<li>Character</li>
<li>Integer</li>
<li>Double (floating point numeric)</li>
<li>Logical</li>
<li>Complex</li>
<li>Raw</li>
</ol>
<p>Python has several data types</p>
<ol>
<li>Int</li>
<li>float</li>
<li>Long</li>
<li>Complex and so on</li>
</ol>
</div>
<div>
<h3>2. R Vector vs Python List</h3>
<p>A common data type in R is the vector. Python has a similar data type, the list</p>
<pre><code><span># R vectors</span>
<span>a</span><span>&lt;-</span><span>c</span><span>(</span><span>4</span>,<span>5</span>,<span>1</span>,<span>3</span>,<span>4</span>,<span>5</span><span>)</span>
<span>print</span><span>(</span><span>a</span><span>[</span><span>3</span><span>]</span><span>)</span></code></pre>
<pre><code>## [1] 1</code></pre>
<pre><code><span>print</span><span>(</span><span>a</span><span>[</span><span>3</span><span>:</span><span>4</span><span>]</span><span>)</span> <span># R does not always need the explicit print. </span></code></pre>
<pre><code>## [1] 1 3</code></pre>
<pre><code><span>#R type of variable</span>
<span>print</span><span>(</span><span>class</span><span>(</span><span>a</span><span>)</span><span>)</span></code></pre>
<pre><code>## [1] &quot;numeric&quot;</code></pre>
<pre><code><span># Length of a</span>
<span>print</span><span>(</span><span>length</span><span>(</span><span>a</span><span>)</span><span>)</span></code></pre>
<pre><code>## [1] 6</code></pre>
<pre><code><span># Python lists</span>
a=[<span>4</span>,<span>5</span>,<span>1</span>,<span>3</span>,<span>4</span>,<span>5</span>] <span># </span>
<span>print</span>(a[<span>2</span>]) <span># Some python IDEs require the explicit print</span>
<span>print</span>(a[<span>2</span>:<span>5</span>])
<span>print</span>(type(a))
<span># Length of a</span>
<span>print</span>(len(a))</code></pre>
<pre><code>## 1
## [1, 3, 4]
## </code></pre></div>