<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Puneet Sharma on Medium]]></title>
        <description><![CDATA[Stories by Puneet Sharma on Medium]]></description>
        <link>https://medium.com/@puneet.988?source=rss-56e5902dd711------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*U3QutkLgp31KcUhW.jpg</url>
            <title>Stories by Puneet Sharma on Medium</title>
            <link>https://medium.com/@puneet.988?source=rss-56e5902dd711------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:00:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@puneet.988/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Beginning with R — The uncharted territory]]></title>
            <link>https://medium.com/data-science/beginning-with-r-the-uncharted-territory-d35eaffff3f3?source=rss-56e5902dd711------2</link>
            <guid isPermaLink="false">https://medium.com/p/d35eaffff3f3</guid>
            <dc:creator><![CDATA[Puneet Sharma]]></dc:creator>
            <pubDate>Wed, 03 Jul 2019 14:37:42 GMT</pubDate>
            <atom:updated>2019-07-05T06:08:13.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PcTu-jNSmwxr82jdEEGtiQ.jpeg" /></figure><p>Coming from a non-programming background and <a href="https://python.org/">python</a> being the first exposure to programming and data analysis, trying to get my hands dirty in <a href="https://www.r-project.org/">R</a> seemed pretty daunting at first. R at times can feel a bit peculiar and unique since it is based on the premise of doing data analysis and statistics rather than software programming which is the case with python. But as I push myself and try to learn the many quirks and leverages of R over python, it sort of gives a different perspective of doing data analysis. Plus, there is a strong edge of using R over python — the vast and contemporary libraries of various statistical methodologies being implemented in R by statisticians world over.</p><p>Besides its quirks, the most interesting IDE developed so far for R — <a href="https://www.rstudio.com/">Rstudio</a> , makes doing data analysis seem like fun activity. The various other things in Rstudio like making reports with support of LaTex and <a href="https://en.wikipedia.org/wiki/HTML">HTML</a> and making static websites using <a href="https://gohugo.io/">HUGO</a> is something which makes life quite easy.</p><p>But to be able to do all this cool stuff we need to first grasp the basics of R which are the building blocks of any complex data analysis pipeline. So let’s start the journey of R. 😃</p><h3>Table of Contents</h3><ul><li>Introduction to R</li><li>R data types</li><li>Handling undefined values</li><li>Operators</li><li>Logical operators</li><li>Data structures — Lists, Vectors, Matrices, Arrays, Factors, Data frames</li></ul><h3>Introduction to R</h3><p>R is a dynamic language developed largely for statistical computing and visualization. It includes various statistical and machine learning packages which are easy to learn and employ for data analysis.</p><h3>R data types</h3><p>When a variable is created in R workspace, R automatically assigns the data type to the variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1dc7e106a8b7594f7b7b24fb285a044/href">https://medium.com/media/a1dc7e106a8b7594f7b7b24fb285a044/href</a></iframe><pre><strong>#</strong><em># [1] 4.2</em></pre><pre><strong>#</strong><em># [1] &quot;Hello!&quot;</em></pre><p>To check the type of variable, use typeof()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d889d3f3dbcf54f59e1a48b3490c2e36/href">https://medium.com/media/d889d3f3dbcf54f59e1a48b3490c2e36/href</a></iframe><pre><strong>#</strong><em># [1] &quot;double&quot;</em></pre><pre><strong>#</strong><em># [1] &quot;character&quot;</em></pre><p>Basic data types are</p><ul><li>String/character</li><li>Number<br> • Integer<br> • Double<br> • Complex</li><li>Boolean/Logical</li></ul><p>A number whether integer or float is always represented as double.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebe828371d948f9e0a4175354458542b/href">https://medium.com/media/ebe828371d948f9e0a4175354458542b/href</a></iframe><pre><strong>#</strong><em># [1] &quot;double&quot;</em></pre><p>For explicit requirement of integer, add suffix L</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2167e985c3f7f9004a43e5529e8b3f5b/href">https://medium.com/media/2167e985c3f7f9004a43e5529e8b3f5b/href</a></iframe><pre><strong>#</strong><em># [1] &quot;integer&quot;</em></pre><h3>Handling undefined values</h3><p>Handling undefined/missing values is somewhat different than python. Python has only NaN values as undefined/missing values. In R, undefined values are basically represented using</p><ul><li>NULL</li><li>NA</li><li>NaN</li></ul><p>All of three work differently.</p><p>NULL which is a null object is used when there is no value present. If there is some value present in the vector or matrix and the value is not usable (fill_value), we use NA or NaN.</p><p>NA or NaN are missing value indicator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed5985503f7f71fa41e0acc4eae3c70e/href">https://medium.com/media/ed5985503f7f71fa41e0acc4eae3c70e/href</a></iframe><pre><strong>#</strong><em># [1] &quot;NULL&quot;</em></pre><pre><strong>#</strong><em># [1] &quot;logical&quot;</em></pre><pre><strong>#</strong><em># [1] &quot;numeric&quot;</em></pre><p>NA comes when there is no TRUE or FALSE i.e. logical indeterminacy. It can also come for missing value.</p><p>NaN means 0/0</p><h3>Operators</h3><ul><li>Multiplication (<strong>*</strong>)</li><li>Division (<strong>/</strong>)</li><li>Addition (<strong>+</strong>)</li><li>Subtraction (<strong>-</strong>)</li><li>Exponent (<strong>^</strong>)</li><li>Modulus (<strong>%%</strong>)</li><li>Integer Division (<strong>%/%</strong>)</li></ul><h3>Logical Operators</h3><ul><li>NOT (<strong>!</strong>)</li><li>Element wise AND (<strong>&amp;</strong>)</li><li>AND (<strong>&amp;&amp;</strong>)</li><li>Element wise OR (<strong>|</strong>)</li><li>OR (<strong>||</strong>)</li><li>In the set (<strong>%in%</strong>)</li></ul><h3>Data Structures</h3><p>In R there are 6 types of data structures</p><ul><li>Lists</li><li>Vectors (or Atomic vectors)</li><li>Matrices</li><li>Arrays</li><li>Factors</li><li>Data frames</li></ul><h4>Lists</h4><p>List in R can hold elements of different types. There is no coercion. A list can contain numeric, characters, boolean, matrices, vectors, arrays, lists etc.</p><p>To create list, use list() argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0f8caa353b077349b07ba54de308445/href">https://medium.com/media/b0f8caa353b077349b07ba54de308445/href</a></iframe><pre><strong>#</strong><em># [[1]]</em><br><strong>#</strong><em># [1] &quot;green&quot;</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[2]]</em><br><strong>#</strong><em># [1] &quot;yellow&quot;</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[3]]</em><br><strong>#</strong><em># [1] 1</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[4]]</em><br><strong>#</strong><em># [1] 2</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[5]]</em><br><strong>#</strong><em># [1] 4 5 6</em></pre><p>To give names to each entry of list, use names() argument.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ce311d76e780690116d7e96a135b4fc/href">https://medium.com/media/6ce311d76e780690116d7e96a135b4fc/href</a></iframe><p>To access a particular entry in list use $</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82db9460b59257c94bffe1aad873d7fc/href">https://medium.com/media/82db9460b59257c94bffe1aad873d7fc/href</a></iframe><pre><strong>#</strong><em># [1] &quot;green&quot;</em></pre><pre><strong>#</strong><em># [1] &quot;yellow&quot;</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d247c22b7019a8b16f18e001e3245adc/href">https://medium.com/media/d247c22b7019a8b16f18e001e3245adc/href</a></iframe><pre><strong>#</strong><em># $A</em><br><strong>#</strong><em># [1] &quot;green&quot;</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a52ed44841ec11f88d1e4aa0598c97c3/href">https://medium.com/media/a52ed44841ec11f88d1e4aa0598c97c3/href</a></iframe><pre><strong>#</strong><em># [1] &quot;green&quot;</em></pre><p>To merge two or more lists, use c()</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce221f84981156343ae48d0436d38d31/href">https://medium.com/media/ce221f84981156343ae48d0436d38d31/href</a></iframe><pre><strong>#</strong><em># [[1]]</em><br><strong>#</strong><em># [1] 1</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[2]]</em><br><strong>#</strong><em># [1] 2</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[3]]</em><br><strong>#</strong><em># [1] 3</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[4]]</em><br><strong>#</strong><em># [1] 4</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[5]]</em><br><strong>#</strong><em># [1] 5</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[6]]</em><br><strong>#</strong><em># [1] 6</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[7]]</em><br><strong>#</strong><em># [1] 7</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># [[8]]</em><br><strong>#</strong><em># [1] 8</em></pre><p>Some predefined lists in R.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac580e99101cd26c1e1b6317c1ec080b/href">https://medium.com/media/ac580e99101cd26c1e1b6317c1ec080b/href</a></iframe><pre><strong>##  [1] &quot;a&quot; &quot;b&quot; &quot;c&quot; &quot;d&quot; &quot;e&quot; &quot;f&quot; &quot;g&quot; &quot;h&quot; &quot;i&quot; &quot;j&quot; &quot;k&quot; &quot;l&quot; &quot;m&quot; &quot;n&quot; &quot;o&quot; &quot;p&quot; &quot;q&quot;</strong><br><strong>## [18] &quot;r&quot; &quot;s&quot; &quot;t&quot; &quot;u&quot; &quot;v&quot; &quot;w&quot; &quot;x&quot; &quot;y&quot; &quot;z&quot;</strong></pre><pre><strong>##  [1] &quot;A&quot; &quot;B&quot; &quot;C&quot; &quot;D&quot; &quot;E&quot; &quot;F&quot; &quot;G&quot; &quot;H&quot; &quot;I&quot; &quot;J&quot; &quot;K&quot; &quot;L&quot; &quot;M&quot; &quot;N&quot; &quot;O&quot; &quot;P&quot; &quot;Q&quot;</strong><br><strong>## [18] &quot;R&quot; &quot;S&quot; &quot;T&quot; &quot;U&quot; &quot;V&quot; &quot;W&quot; &quot;X&quot; &quot;Y&quot; &quot;Z&quot;</strong></pre><pre><strong>##  [1] &quot;Jan&quot; &quot;Feb&quot; &quot;Mar&quot; &quot;Apr&quot; &quot;May&quot; &quot;Jun&quot; &quot;Jul&quot; &quot;Aug&quot; &quot;Sep&quot; &quot;Oct&quot; &quot;Nov&quot;</strong><br><strong>## [12] &quot;Dec&quot;</strong></pre><pre><strong>##  [1] &quot;January&quot;   &quot;February&quot;  &quot;March&quot;     &quot;April&quot;     &quot;May&quot;      </strong><br><strong>##  [6] &quot;June&quot;      &quot;July&quot;      &quot;August&quot;    &quot;September&quot; &quot;October&quot;  </strong><br><strong>## [11] &quot;November&quot;  &quot;December&quot;</strong></pre><h4>Vectors</h4><p>To create a vector, we use c() function. It basically concatenates things like a list in python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f5ed708f4c5165dae725c1796c001bf/href">https://medium.com/media/6f5ed708f4c5165dae725c1796c001bf/href</a></iframe><pre><strong>## [1] &quot;1&quot;     &quot;2&quot;     &quot;3&quot;     &quot;4&quot;     &quot;5.4&quot;   &quot;hello&quot; &quot;TRUE&quot;  &quot;FALSE&quot;</strong></pre><p>As we can see, a vector can have any data type, be it number, character or boolean. But we notice something. All the elements in the vector are coerced to character type because the vector contains a string &quot;hello&quot;. This is the effect of implicit coercion.</p><p>For strictly making a numeric vector, use vector() function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91a464c86fbaf9bd67f155f40742c722/href">https://medium.com/media/91a464c86fbaf9bd67f155f40742c722/href</a></iframe><pre><strong>#</strong><em>#  [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0</em></pre><p>We can use such a vector to preallocate a vector which can be used for appending values from a for loop which is faster than appending values to an empty vector since every time a value is appended in an empty vector, R makes a copy of it thus slowing the whole process.</p><p><strong>Coercion</strong> — Objects like vectors, data frames etc. can be coerced to different classess using as.class function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1da8f55fd72a950a3bc247405eddf5c6/href">https://medium.com/media/1da8f55fd72a950a3bc247405eddf5c6/href</a></iframe><pre><strong>#</strong><em># [1] &quot;numeric&quot;</em></pre><pre><strong>#</strong><em># [1] &quot;character&quot;</em></pre><pre><strong>#</strong><em># [1] &quot;logical&quot;</em></pre><h4>Matrices</h4><p>Matrix is same as a vector except it has an additional attribute of dimension. It is a two dimensional data structure.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7979af85000631cf38a2facbb573531b/href">https://medium.com/media/7979af85000631cf38a2facbb573531b/href</a></iframe><pre><strong>#</strong><em>#      [,1] [,2] [,3]</em><br><strong>#</strong><em># [1,]    6    8    6</em><br><strong>#</strong><em># [2,]    2    3    8</em><br><strong>#</strong><em># [3,]    6    2    0</em></pre><pre><strong>#</strong><em># $dim</em><br><strong>#</strong><em># [1] 3 3</em></pre><p>Matrices start filling row wise. Whereas in python, a matrix starts filling column wise.</p><p>In R, we can pass the names of rows and columns.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2289b9028208ae47a2d0747a0d9f1b84/href">https://medium.com/media/2289b9028208ae47a2d0747a0d9f1b84/href</a></iframe><pre><strong>#</strong><em>#   x y z</em><br><strong>#</strong><em># a 6 8 6</em><br><strong>#</strong><em># b 2 3 8</em><br><strong>#</strong><em># c 6 2 0</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf8334df073f05f76f31aa8debd23822/href">https://medium.com/media/cf8334df073f05f76f31aa8debd23822/href</a></iframe><pre><strong>## [1] &quot;x&quot; &quot;y&quot; &quot;z&quot;</strong></pre><pre><strong>## [1] &quot;a&quot; &quot;b&quot; &quot;c&quot;</strong></pre><p>To access the elements of a matrix, use square brackets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae6fe8edb2b5fa32e31e18b2542ba2a9/href">https://medium.com/media/ae6fe8edb2b5fa32e31e18b2542ba2a9/href</a></iframe><pre><strong>#</strong><em># [1] 3</em></pre><pre><strong>#</strong><em>#   x y</em><br><strong>#</strong><em># b 2 3</em><br><strong>#</strong><em># c 6 2</em></pre><p>But a[2,] (2nd row) or a[,2] (2nd column) gives a vector i.e. it tries to return the simplest data structure. To avoid this i.e. to get a matrix, use drop = FALSE</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d862a57a3627a11c1248f15826663dd7/href">https://medium.com/media/d862a57a3627a11c1248f15826663dd7/href</a></iframe><pre><strong>#</strong><em># x y z </em><br><strong>#</strong><em># 2 3 8</em></pre><pre><strong>#</strong><em># NULL</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dcb53294c429f93dc143af1a5b7f92b3/href">https://medium.com/media/dcb53294c429f93dc143af1a5b7f92b3/href</a></iframe><pre><strong>#</strong><em>#   x y z</em><br><strong>#</strong><em># b 2 3 8</em></pre><pre><strong>#</strong><em># [1] 1 3</em></pre><p>Specific indexing can also be done.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2d14be1ae9c53e2b33d17bdee5ec6878/href">https://medium.com/media/2d14be1ae9c53e2b33d17bdee5ec6878/href</a></iframe><pre><strong>#</strong><em># [1] 6 2 8 2</em></pre><p>You can also do indexing using logical vectors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e521db1877930158c934722545fdc1be/href">https://medium.com/media/e521db1877930158c934722545fdc1be/href</a></iframe><pre><strong>#</strong><em>#   x y</em><br><strong>#</strong><em># a 6 8</em><br><strong>#</strong><em># c 6 2</em></pre><p>To transpose a matrix use t(a)</p><p>To combine vectors or matrices, use rbind or cbind</p><p>Dimension of a matrix can also be changed (reshape).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2390d8751a98b346bcd9426922d90ee8/href">https://medium.com/media/2390d8751a98b346bcd9426922d90ee8/href</a></iframe><pre><strong>#</strong><em># [1] 1 9</em></pre><h4>Arrays</h4><p>Array is an object which can hold multidimensional data. Matrices are a subset of arrays as in they are two dimensional arrays. So, together with an attribute of dimension i.e. dim, arrays also have attribute dimnames. Array is simply a multidimensional data structure.</p><p>Its syntax is a &lt;- array(data, dim = c(x,y,z,t...))</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd88e38efaec710a6c26386f08e0bc9b/href">https://medium.com/media/fd88e38efaec710a6c26386f08e0bc9b/href</a></iframe><pre><strong>#</strong><em># , , 1</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2] [,3] [,4]</em><br><strong>#</strong><em># [1,]    1    4    7   10</em><br><strong>#</strong><em># [2,]    2    5    8   11</em><br><strong>#</strong><em># [3,]    3    6    9   12</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , 2</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2] [,3] [,4]</em><br><strong>#</strong><em># [1,]   13   16   19   22</em><br><strong>#</strong><em># [2,]   14   17   20   23</em><br><strong>#</strong><em># [3,]   15   18   21   24</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1265cef8cbb533cefd120acdaf980df/href">https://medium.com/media/a1265cef8cbb533cefd120acdaf980df/href</a></iframe><pre><strong>#</strong><em># , , 1</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2]</em><br><strong>#</strong><em># [1,]   10   30</em><br><strong>#</strong><em># [2,]   20   40</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , 2</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2]</em><br><strong>#</strong><em># [1,]   12   14</em><br><strong>#</strong><em># [2,]   13   15</em></pre><p>To define labels for different dimensions, use dimnames</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8dde5b696d4646a3edee4610e3341284/href">https://medium.com/media/8dde5b696d4646a3edee4610e3341284/href</a></iframe><pre><strong>#</strong><em># , , g</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#    d  e</em><br><strong>#</strong><em># a 10 30</em><br><strong>#</strong><em># b 20 40</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , h</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#    d  e</em><br><strong>#</strong><em># a 12 14</em><br><strong>#</strong><em># b 13 15</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a90997a6e11777dff5123b85bc053d3f/href">https://medium.com/media/a90997a6e11777dff5123b85bc053d3f/href</a></iframe><pre><strong>#</strong><em># , , 1</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2] [,3]</em><br><strong>#</strong><em># [1,]    1    4    7</em><br><strong>#</strong><em># [2,]    2    5    8</em><br><strong>#</strong><em># [3,]    3    6    9</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , 2</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2] [,3]</em><br><strong>#</strong><em># [1,]   10   13   16</em><br><strong>#</strong><em># [2,]   11   14   17</em><br><strong>#</strong><em># [3,]   12   15   18</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , 3</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2] [,3]</em><br><strong>#</strong><em># [1,]   19   22   25</em><br><strong>#</strong><em># [2,]   20   23   26</em><br><strong>#</strong><em># [3,]   21   24   27</em></pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37d836189691ff6127f4daa1c55b5fa1/href">https://medium.com/media/37d836189691ff6127f4daa1c55b5fa1/href</a></iframe><pre><strong>#</strong><em># $dim</em><br><strong>#</strong><em># [1] 2 2 3</em></pre><pre><strong>#</strong><em># , , 1</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2]</em><br><strong>#</strong><em># [1,]    1    4</em><br><strong>#</strong><em># [2,]    2    5</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , 2</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2]</em><br><strong>#</strong><em># [1,]   10   13</em><br><strong>#</strong><em># [2,]   11   14</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># , , 3</em><br><strong>#</strong><em># </em><br><strong>#</strong><em>#      [,1] [,2]</em><br><strong>#</strong><em># [1,]   19   22</em><br><strong>#</strong><em># [2,]   20   23</em></pre><h4>Factors</h4><p>For the representation of categorical data, R has specific object called factors. Factors are basically integers and have labels associated with them. So, a particular number of factors are associated with a particular label. These labels are called levels. Factors look like characters but are integers in reality. Further uses of Factors are to sort all the categorical datasets according to one categorical dataset.</p><p>factor() command is used to create a factor object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a27eb8fbf531cf86f63d81eacaa090d0/href">https://medium.com/media/a27eb8fbf531cf86f63d81eacaa090d0/href</a></iframe><pre><strong>#</strong><em># $levels</em><br><strong>#</strong><em># [1] &quot;apple&quot;  &quot;banana&quot; &quot;orange&quot;</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># $class</em><br><strong>#</strong><em># [1] &quot;factor&quot;</em></pre><p>The levels are by default unordered. To order them you can define the levels.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8c55a22f8fe26c0e39a55aa4159c352/href">https://medium.com/media/c8c55a22f8fe26c0e39a55aa4159c352/href</a></iframe><pre><strong>#</strong><em># $levels</em><br><strong>#</strong><em># [1] &quot;apple&quot;  &quot;orange&quot; &quot;banana&quot;</em><br><strong>#</strong><em># </em><br><strong>#</strong><em># $class</em><br><strong>#</strong><em># [1] &quot;factor</em></pre><h4>Dataframes</h4><p>Dataframes are used to store tabular data. Lists of equal length are stored in dataframes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4d9ae83d163f906a2368d0a5581176f/href">https://medium.com/media/a4d9ae83d163f906a2368d0a5581176f/href</a></iframe><pre><strong>#</strong><em>#     city rank</em><br><strong>#</strong><em># 1 Jaipur    2</em><br><strong>#</strong><em># 2  Jammu    3</em></pre><p>The data stored can be of different type. One column may be character, another may be factors and so on. But each column must have same type of data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d35eaffff3f3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/beginning-with-r-the-uncharted-territory-d35eaffff3f3">Beginning with R — The uncharted territory</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>