

{"id":5531,"date":"2018-01-19T10:17:06","date_gmt":"2018-01-19T04:47:06","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=5531"},"modified":"2021-08-25T22:32:54","modified_gmt":"2021-08-25T17:02:54","slug":"data-structures-in-r","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/","title":{"rendered":"Data Structures in R &#8211; The most essential concept for R Aspirants!"},"content":{"rendered":"<p>In this article, we will study the different types of data structures in R programming. We will also understand their use and implementation with the help of examples.<\/p>\n<p>Without wasting any time, let&#8217;s quickly start.<\/p>\n<h2>Introduction to Data Structures in R<\/h2>\n<p>In any programming language, if you are doing programming, you need to use different variables to store different data. Moreover, variables are reserved in a memory location to store values. Also, this implies that, once you create a variable you reserve some area in memory. Further, data structures are the only way of arranging data so it can be used efficiently on a computer.<\/p>\n<p>If we see in contrast to different programming languages like C and Java, R doesn\u2019t have variables declared as some data type. Further, the variables are appointed with R-objects and the knowledge form of the R-object becomes the datatype of the variable. There are many types of R-objects. The popularly used ones are:<\/p>\n<ul>\n<li>Vector<\/li>\n<li>Matrix<\/li>\n<li>Array<\/li>\n<li>Lists<\/li>\n<li>Data Frames<\/li>\n<\/ul>\n<p>Now, we will discuss each of these R-objects in brief.<\/p>\n<h3>1. R Vector<\/h3>\n<p>Vector is the most basic data structure in R programming language.\u00a0It comes in two parts: <b>Atomic vectors<\/b> and <b>Lists.<\/b> They have three common properties:<\/p>\n<ul>\n<li>Type function &#8211; what actually it is?<\/li>\n<li>Length function &#8211; how many elements does it contain.<\/li>\n<li>Attribute function &#8211; extra arbitrary metadata.<\/li>\n<\/ul>\n<p>These elements have different types. For instance, atomic vectors must share the same type. On the contrary, elements that are present in a list can have different data types. <em>We have discussed\u00a0<strong><a href=\"https:\/\/data-flair.training\/blogs\/r-list-tutorial\/\">every concept of R List<\/a><\/strong> in our previous article, here we are going to understand only Atomic Vectors.<\/em><\/p>\n<p><strong>Atomic Vectors<\/strong><\/p>\n<p>There are four common types of R Atomic Vectors:<\/p>\n<ul>\n<li>Numeric Data Type<\/li>\n<li>Integer Data Type<\/li>\n<li>Character Data Type<\/li>\n<li>Logical Data Type<\/li>\n<\/ul>\n<h3>2. R Matrix<\/h3>\n<p>First of all, we will discuss what exactly matrices in data structures in R mean. <em>A matrix is a two-dimensional rectangular data set and thus it can be created using vector input to the matrix function.<\/em> In addition, a matrix is a collection of numbers arranged into a fixed number of rows and columns. Usually, the numbers are the real numbers. By using a matrix function, we can reproduce a memory representation of the matrix in R. Hence, the data elements must be of the same basic type.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; mat1 &lt;- matrix(1:4, nrow = 2, ncol = 2)  #Author DataFlair\r\n&gt; mat1\r\n&gt; mat2 &lt;- matrix(4:7, nrow = 2, ncol = 2)\r\n&gt; mat2<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65016\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix.jpg\" alt=\"mat1 matrix\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat1-matrix-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>We can access the element present at the mth row and nth column as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; mat1[1,2]     #Author DataFlair\r\n&gt;\u00a0mat2[2,1]<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65018\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12.jpg\" alt=\"mat 1 1,2\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-1-12-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p>We can also extract the entire mth row and nth row separately as follows:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; mat1[2, ]  #Author DataFlair\r\n&gt; mat1[, 2]  #Author DataFlair<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65022\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12.jpg\" alt=\"mat 12,\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mat-12-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>Before proceeding ahead, please confirm that you have completed &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/r-matrix-operations-applications\/\">R Matrix Operations<\/a><\/strong><\/em><\/p>\n<h3>Uses of Matrices<\/h3>\n<p>Method to solve the matrices:<\/p>\n<h4><strong>1.<\/strong> Adding<\/h4>\n<p>In addition of two matrices, we add the numbers in matching positions:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; mat1 + mat2    #Author DataFlair\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65023\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum.jpg\" alt=\"Sum - R Data Structures\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Sum-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4>2.<strong> Subtracting<\/strong><\/h4>\n<p>In subtraction of two matrices, we subtract the numbers in matching positions:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; mat1 - mat2       #Author DataFlair\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65024\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction.jpg\" alt=\"subtraction - R Data Structures\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/subtraction-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4><strong>3.<\/strong> Multiply<strong> by a constant<\/strong><\/h4>\n<p>We can multiply by some constant value like so:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; 4 * mat1      #Author DataFlair<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-65025 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult.jpg\" alt=\"multiply - R Data Structures\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/mult-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4><strong>4. Divid<\/strong>i<strong>ng<\/strong><\/h4>\n<p>In division of two matrices, divides the numbers in matching positions<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; (mat1\/mat2)    #Author DataFlair\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65122\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division.png\" alt=\"matrix division - R Data Structures\" width=\"1300\" height=\"738\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division.png 1300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division-150x85.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division-300x170.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division-768x436.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division-1024x581.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/matrix-division-520x295.png 520w\" sizes=\"auto, (max-width: 1300px) 100vw, 1300px\" \/><\/a><\/p>\n<h4><strong>5.<\/strong> Transposing<\/h4>\n<p>The transpose of a matrix is a matrix with the rows and columns swapped, we can find the transpose of a matrix with the t() function:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; t(mat1)     #DataFlair\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65028\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing.jpg\" alt=\"transposing\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/transposing-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4><strong>6. Identity<\/strong> Matrix<\/h4>\n<p>We can find the nxn identity matrix using the diag(n) function.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; diag(4)    #Author DataFlair\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65029\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix.jpg\" alt=\"identity matrix - R Data Structures\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/identity-matrix-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><em><strong>A must learn concept to ease your R programming journey &#8211; <a href=\"https:\/\/data-flair.training\/blogs\/r-factor-functions\/\">R Factor Functions<\/a><\/strong><\/em><\/p>\n<h3>Applications of Matrices<\/h3>\n<ul>\n<li>Matrices are used for<strong> carrying out geological surveys<\/strong>. We can represent information in the form of matrices that can be used for<em> plotting graphs, performing statistical operations,<\/em> etc.<\/li>\n<li>To <strong>represent the real-world data<\/strong> is like traits of people\u2019s population. They are the best representation method for plotting common survey things.<\/li>\n<li>In robotics and automation, matrices are the <strong>best elements for the robot movements<\/strong>.<\/li>\n<li>Matrices are used in <strong>calculating the gross domestic products<\/strong> in economics. Therefore, it helps in calculating goods product efficiency.<\/li>\n<li>In computer-based applications, matrices play a vital role in the <strong>projection of a three-dimensional image into a two-dimensional screen<\/strong> creating realistic seeming motions.<\/li>\n<li>In physical related applications, matrices can be applied in the <strong>study of an electrical circuit<\/strong>.<\/li>\n<\/ul>\n<h3>3. R Array<\/h3>\n<p>In R Programming, arrays are multi-dimensional Data structures. In an array, data is stored in the form of matrices, row, and as well as in columns. We can use the <em>matrix level, row index, and column index<\/em> to access the matrix elements.<\/p>\n<p>Arrays in R are the data objects which can store data in more than two dimensions. An array is created using the <em>array()<\/em> function. We can use vectors as input. To create an array, we can use these values in the dim parameter.<\/p>\n<p><b>For example:<\/b><\/p>\n<p>In this following example, we will create an array in R of two 3\u00d73 matrices each with 3 rows and 3 columns.<br \/>\n<b><\/b><\/p>\n<p><b># Create two vectors of different lengths.<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; vec1 &lt;- c(1,2,4)     #Author DataFlair\r\n&gt; vec2 &lt;- c(15,17,27,3,10,11)\r\n&gt; output &lt;- array(c(vec1,vec2),dim = c(3,3,2))\r\n&gt; output<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65032\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array.jpg\" alt=\"Data Structures in R - Array\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-Array-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h3>Different Operations on Rows and Columns<\/h3>\n<h4>1. Naming Columns And Rows<\/h4>\n<p>We can give names to the<em> rows, columns, and matrices<\/em> in the array by using the dimnames parameter.<br \/>\n<b><\/b><\/p>\n<p><b># Create two vectors of different lengths.<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vec1 &lt;- c(1,2,4)\r\nvec2 &lt;- c(15,17,27,3,10,11)\r\ncolumn_names &lt;- c(\u201ccol1\u2033,\u201dcol2\u2033,\u201dcol3\u201d)\r\nrow_names &lt;- c(\u201crow1\u2033,\u201drow2\u2033,\u201drow3\u201d)\r\nmatrix_names &lt;- c(\u201cMat1\u2033,\u201dMat2\u201d)\r\n\r\n<\/pre>\n<p><b># Take these vectors as input to the array.<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">output &lt;- array(c(vec1,vec2),dim = c(3,3,2),dimnames = list(row_names,column_names,\r\nmatrix_names))\r\noutput<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65034\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array.jpg\" alt=\"Naming Columns and Rows of R Array\" width=\"1186\" height=\"677\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array.jpg 1186w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array-1024x585.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Naming-Columns-and-Rows-of-R-Array-520x297.jpg 520w\" sizes=\"auto, (max-width: 1186px) 100vw, 1186px\" \/><\/a><\/p>\n<h4>2. Accessing Array Elements<br \/>\n<b><\/b><\/h4>\n<p><b># We will create two vectors of different lengths.<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">vec1 &lt;- c(1,2,4)\r\nvec2 &lt;- c(15,17,27,3,10,11)\r\nrow_names &lt;- c(\u201crow1\u2033,\u201drow2\u2033,\u201drow3\u201d)\r\ncol_names &lt;- c(\u201ccol1\u2033,\u201dcol2\u2033,\u201dcol3\u201d)\r\nmatrix_names &lt;- c(\u201cMat1\u2033,\u201dMat2\u201d)\r\noutput\u00a0&lt;-\u00a0array(c(vec1,vec2),dim\u00a0=\u00a0c(3,3,2),dimnames\u00a0=\u00a0list(row_names,col_names,matrix_names))\r\noutput<b><\/b><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65038\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements.jpg\" alt=\"Accessing Array Elements - R Data Structures\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; output[3,,2] #Author DataFlair\r\n&gt; output[1,3,1] #Print the element in the 1st row and 3rd column of the 1st matrix\r\n&gt; output[,,2] #Print the 2nd Matrix<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65037\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2.jpg\" alt=\"Accessing Array Elements 2\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Accessing-Array-Elements-2-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4>3. Manipulating Array Elements<\/h4>\n<p>As the array is made up of matrices in multiple dimensions, the operations on elements of an array are carried out by accessing elements of the matrices.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; vec1 &lt;- c(1,2,3)        #Author DataFlair   \r\n&gt; vec2 &lt;- c(4,5,6,7,8,9)\r\n&gt; arr1 &lt;- array(c(vec1,vec2),dim = c(3,3,2))\r\n&gt; vec3 &lt;- c(3,2,1)\r\n&gt; vec4 &lt;- c(9,8,7,6,5,4)\r\n&gt; arr2 &lt;- array(c(vec3,vec4),dim = c(3,3,2))\r\n&gt; mat1 &lt;- arr1[,,2]  #Creating Matrix out out array\r\n&gt; mat2 &lt;- arr2[,,2]\r\n&gt; output &lt;- mat1 + mat2\r\n&gt; output<b><\/b><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65039\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements.jpg\" alt=\"Manipulating Array Elements - R Data Structures\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Manipulating-Array-Elements-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<h4>4. Calculations across R Array Elements<\/h4>\n<p>We will be using the <em>apply()<\/em> function for calculations in an array in <a href=\"https:\/\/www.r-project.org\/foundation\/\">R<\/a>.<br \/>\n<b><\/b><\/p>\n<p><b>Syntax:<\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">apply(x, margin, fun)<\/pre>\n<p><b>Following is the description of the parameters used:<\/b><\/p>\n<ul>\n<li>x is an array.<\/li>\n<li>A margin is the name of the dataset used.<\/li>\n<li>fun is the function to be applied to the elements of the array.<\/li>\n<\/ul>\n<p><b>For example<\/b>:<\/p>\n<p>We use the apply() function below in different ways to calculate the sum of the elements in the rows of an array across all the matrices.<br \/>\n<b><\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; vec1 &lt;- c(1,2,3)        #Author DataFlair   \r\n&gt; vec2 &lt;- c(4,5,6,7,8,9)\r\n&gt; array_new &lt;- array(c(vec1,vec2),dim = c(3,3,2))\r\n&gt; array_new\r\n\r\n&gt; output &lt;- apply(array_new, c(1), sum)\r\n&gt; output<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65040\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements.jpg\" alt=\"Calculations Across R Array Elements\" width=\"1299\" height=\"741\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements.jpg 1299w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Calculations-Across-R-Array-Elements-520x297.jpg 520w\" sizes=\"auto, (max-width: 1299px) 100vw, 1299px\" \/><\/a><\/p>\n<p><b><\/b><em><strong>Explore a complete <a href=\"https:\/\/data-flair.training\/blogs\/r-array\/\">tutorial on R Array Function<\/a><\/strong><\/em><\/p>\n<h3>4. List in R<\/h3>\n<p>Lists are the objects which contain elements of different types \u2013 like <em>strings, numbers, vectors and another list inside them.<\/em> A list can also contain a matrix or a function as its elements. In other words, a list is a generic vector containing other objects. A list is created using the list() function.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>The variable x is containing copies of three vectors n, s, b and a numeric value 3.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; num_list = c(3,4,5)    #Author DataFlair\r\n&gt; char_list = c(\"a\", \"b\", \"c\", \"d\", \"e\")\r\n&gt; logic_list = c(TRUE, TRUE, FALSE, TRUE)\r\n&gt; out_list = list(num_list, char_list, logic_list, 3)\r\n&gt; out_list<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65041\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list.jpg\" alt=\"num_list - R Data Structures\" width=\"1186\" height=\"676\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list.jpg 1186w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-150x85.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-520x296.jpg 520w\" sizes=\"auto, (max-width: 1186px) 100vw, 1186px\" \/><\/a><\/p>\n<h3>5. Data Frame in R<\/h3>\n<p>First of all, we are going to discuss where the concept of data frame came. The concept comes from the world of the statistical software used in empirical research. It generally refers to <em>tabular data: a data structure representing the cases (rows), each of which consists of numbers of observation or measurement (columns).<\/em><\/p>\n<p>A data frame is used for storing data tables. It is a list of vectors of equal length.<\/p>\n<p><strong>For example:<\/strong><\/p>\n<p>The following variable df is a data frame containing three variables n, s, b.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt; num_list = c(3,4,5)    #Author DataFlair\r\n&gt; char_list = c(\"a\", \"b\", \"c\")\r\n&gt; logic_list = c(TRUE, FALSE, TRUE)\r\n&gt; data_frame = data.frame(num_list, char_list, logic_list)\r\n&gt; data_frame<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-65042\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5.jpg\" alt=\"num_list c 3 4 5 - R Data Structures\" width=\"1187\" height=\"677\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5.jpg 1187w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5-150x86.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5-300x171.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5-768x438.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5-1024x584.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/num_list-c-3-4-5-520x297.jpg 520w\" sizes=\"auto, (max-width: 1187px) 100vw, 1187px\" \/><\/a><\/p>\n<p>A data frame is an array. Unlike an array, the data we store in the columns of the data frame can be of various types. That is, one column might be a numeric variable, another might be a factor, and a third might be a character variable. All columns have to be of the same length.<\/p>\n<p><strong>C<\/strong><strong>haracteristics of a Data Frame:<\/strong><\/p>\n<ul>\n<li>The column names should be non-empty.<\/li>\n<li>The row names should be unique.<\/li>\n<li>The data stored in a data frame can be of <em>numeric, factor or character type.<\/em><\/li>\n<li>Each column should contain the same number of data items.<\/li>\n<\/ul>\n<p>Datasets imported in R are stored as data frames by default.<\/p>\n<p><em><strong>Get to know everything about <a href=\"https:\/\/data-flair.training\/blogs\/r-data-frame\/\">R Data Frame Concept<\/a>\u00a0in detail<\/strong><\/em><\/p>\n<h2>Summary<\/h2>\n<p>We learned about all the types of data structures in R Programming along with their use, implementation, and examples. We hope you understood every concept thoroughly.<\/p>\n<p>Still, if you have any doubts related to any of the topics, feel free to share in the comment section below.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2169,&quot;href&quot;:&quot;https:\\\/\\\/www.r-project.org\\\/foundation&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20251001075238\\\/https:\\\/\\\/www.r-project.org\\\/foundation\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-11 00:43:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-20 06:25:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-26 01:06:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-30 10:24:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-05 06:41:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-08 22:31:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-12 05:46:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 15:20:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-18 17:45:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-24 04:19:47&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-27 04:57:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-30 14:28:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-03 04:38:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-07 08:31:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 15:37:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-16 04:55:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 17:45:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 00:55:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 06:56:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 20:59:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 00:48:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-10 09:01:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 17:05:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 15:22:34&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 16:29:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 17:07:00&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 10:49:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 00:45:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 06:25:35&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-20 11:43:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-23 15:54:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-28 17:33:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-04 00:56:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-09 06:45:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-12 14:29:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-15 16:58:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-19 12:18:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-23 07:04:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-29 08:36:27&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-02 15:52:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-06 05:56:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-09 12:41:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-12 20:58:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-18 04:08:14&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-06-22 10:36:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-27 08:08:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-01 01:53:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-04 14:35:44&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-07-08 09:19:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-12 10:53:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-15 23:41:16&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-07-19 12:16:56&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-07-23 12:28:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-07-27 12:46:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-08-02 05:08:23&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-08-06 02:03:07&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-08-06 02:03:07&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will study the different types of data structures in R programming. We will also understand their use and implementation with the help of examples. Without wasting any time, let&#8217;s quickly&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":65071,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[3471,11154,11174,11221,11226,20361],"class_list":["post-5531","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","tag-data-structures-in-r","tag-r-array","tag-r-data-structures","tag-r-lists","tag-r-matrix","tag-r-vector"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Data Structures in R - The most essential concept for R Aspirants! - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn about all the types of Data Structures in R Programming with their features, implementation and examples. Data Structures are the only way of arranging data so it can be used efficiently on a computer.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Structures in R - The most essential concept for R Aspirants! - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn about all the types of Data Structures in R Programming with their features, implementation and examples. Data Structures are the only way of arranging data so it can be used efficiently on a computer.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-19T04:47:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-25T17:02:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Structures in R - The most essential concept for R Aspirants! - DataFlair","description":"Learn about all the types of Data Structures in R Programming with their features, implementation and examples. Data Structures are the only way of arranging data so it can be used efficiently on a computer.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/","og_locale":"en_US","og_type":"article","og_title":"Data Structures in R - The most essential concept for R Aspirants! - DataFlair","og_description":"Learn about all the types of Data Structures in R Programming with their features, implementation and examples. Data Structures are the only way of arranging data so it can be used efficiently on a computer.","og_url":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-19T04:47:06+00:00","article_modified_time":"2021-08-25T17:02:54+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"Data Structures in R &#8211; The most essential concept for R Aspirants!","datePublished":"2018-01-19T04:47:06+00:00","dateModified":"2021-08-25T17:02:54+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/"},"wordCount":1317,"commentCount":2,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-01-1.jpg","keywords":["data structures in R","R array","R data structures","R lists","R matrix","R Vector"],"articleSection":["R Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/","url":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/","name":"Data Structures in R - The most essential concept for R Aspirants! - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-01-1.jpg","datePublished":"2018-01-19T04:47:06+00:00","dateModified":"2021-08-25T17:02:54+00:00","description":"Learn about all the types of Data Structures in R Programming with their features, implementation and examples. Data Structures are the only way of arranging data so it can be used efficiently on a computer.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/data-structures-in-r\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Data-Structures-in-R-01-1.jpg","width":802,"height":420,"caption":"Data Structures in R"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/data-structures-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"R Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/r\/"},{"@type":"ListItem","position":3,"name":"Data Structures in R &#8211; The most essential concept for R Aspirants!"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=5531"}],"version-history":[{"count":14,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5531\/revisions"}],"predecessor-version":[{"id":86542,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/5531\/revisions\/86542"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/65071"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=5531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=5531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=5531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}