A data structure is a particular way of organizing data in a computer so that it can be used effectively. The idea is to reduce the space and time complexities of different tasks. Data structures in R programming are tools for holding multiple values.
R’s base data structures are often organized by their dimensionality (1D, 2D, or nD) and whether they’re homogeneous (all elements must be of the identical type) or heterogeneous (the elements are often of various types). This gives rise to the five data types which are most frequently utilized in data analysis. the subsequent table shows a transparent cut view of those data structures.
The most essential data structures used in R include:
A vector is an ordered collection of basic data types of a given length. The only key thing here is all the elements of a vector must be of the identical data type e.g homogenous data structures. Vectors are one-dimensional data structures.
 1 3 5 7 8
A list is a generic object consisting of an ordered collection of objects. Lists are heterogeneous data structures. These are also one-dimensional data structures. A list can be a list of vectors, list of matrices, a list of characters and a list of functions and so on.
[]  1 2 3 4 []  "Debi" "Sandeep" "Subham" "Shiba" []  4
Dataframes are generic data objects of R which are used to store the tabular data. Dataframes are the foremost popular data objects in R programming because we are comfortable in seeing the data within the tabular form. They are two-dimensional, heterogeneous data structures. These are lists of vectors of equal lengths.
Data frames have the following constraints placed upon them:
- A data-frame must have column names and every row should have a unique name.
- Each column must have the identical number of items.
- Each item in a single column must be of the same data type.
- Different columns may have different data types.
To create a data frame we use the data.frame() function.
Name Language Age 1 Amiya R 22 2 Raj Python 25 3 Asish Java 45
A matrix is a rectangular arrangement of numbers in rows and columns. In a matrix, as we know rows are the ones that run horizontally and columns are the ones that run vertically. Matrices are two-dimensional, homogeneous data structures.
Now, let’s see how to create a matrix in R. To create a matrix in R you need to use the function called matrix. The arguments to this matrix() are the set of elements in the vector. You have to pass how many numbers of rows and how many numbers of columns you want to have in your matrix and this is the important point you have to remember that by default, matrices are in column-wise order.
[,1] [,2] [,3] [1,] 1 2 3 [2,] 4 5 6 [3,] 7 8 9
Arrays are the R data objects which store the data in more than two dimensions. Arrays are n-dimensional data structures. For example, if we create an array of dimensions (2, 3, 3) then it creates 3 rectangular matrices each with 2 rows and 3 columns. They are homogeneous data structures.
Now, let’s see how to create arrays in R. To create an array in R you need to use the function called array(). The arguments to this array() are the set of elements in vectors and you have to pass a vector containing the dimensions of the array.
, , 1 [,1] [,2] [1,] 1 3 [2,] 2 4 , , 2 [,1] [,2] [1,] 5 7 [2,] 6 8
Factors are the data objects which are used to categorize the data and store it as levels. They are useful for storing categorical data. They can store both strings and integers. They are useful to categorize unique values in columns like “TRUE” or “FALSE”, or “MALE” or “FEMALE”, etc.. They are useful in data analysis for statistical modeling.
Now, let’s see how to create factors in R. To create a factor in R you need to use the function called factor(). The argument to this factor() is the vector.
 Male Female Male Male Female Male Female Levels: Female Male
- Data Wrangling in R Programming - Data Transformation
- Convert an Object to Data Frame in R Programming - as.data.frame() Function
- Check if the Object is a Data Frame in R Programming - is.data.frame() Function
- Convert a Data Frame into a Numeric Matrix in R Programming - data.matrix() Function
- Modify Data of a Data Frame with an Expression in R Programming - with() Function
- Generate a set of Sample data from a Data set in R Programming - sample() Function
- Data Handling in R Programming
- Data Reshaping in R Programming
- R Programming for Data Science
- Reading Tabular Data from files in R Programming
- How To Import Data from a File in R Programming
- Accessing variables of a data frame in R Programming - attach() and detach() function
- Comparing values of data frames in R Programming - all_equal() Function
- Convert type of data object in R Programming - type.convert() Function
- Exporting Data from scripts in R Programming
- Create Matrix and Data Frame from Lists in R Programming
- Check if Object is of the Character Data type in R Programming - is.character() Function
- Get Transpose of a Matrix or Data Frame in R Programming - t() Function
- Create a Data Frame of all the Combinations of Vectors passed as Argument in R Programming - expand.grid() Function
- Data Wrangling in R Programming - Working with Tibbles
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.