Data Structures in R

In this tutorial, you will learn about what are different data structures in R? To understand the R language, you will need to understand the basic data types and data structures and how to use them.

Data Structures in R

A data structure is a way of organizing the data in such a way that we can use it more efficiently in R programming language.

In R, there are five basic data structures.

  • Vector
  • matrix
  • array
  • data frame
  • list
Dat Structures in R
Dat Structures in R

Basically these data structures are classified into two types, namely, atomic (homogeneous) and generic (heterogeneous).

In atomic data structure all the stored objects are of the same type, whereas in generic data structure all the stored objects may be mixture of different types.

Dimension Atomic Generic
1 Vector List
2 Matrix data frame
n Array

Each object in R has a class or data type. Class determines how functions treat them. There are five basic classes of an objects.

  • Integer
  • Numeric (Real numbers)
  • Logical (True/False)
  • Character
  • Complex

Learn more about data types in R in my tutorials about
data types in R.

Vectors in R

Vectors is a basic data structure in R. Vector is an atomic (homogeneous) data structure, where all the stored objects are of same type. Vector can be defined as a set of constants or scalars of same type arranged in a one-dimensional array.

vectors in R
vectors in R

Learn more about vectors in R in my tutorials about Vectors in R.

Matrix in R

A matrix is a two-dimensional data structure in R. It is a set of elements appearing in rows and columns. Matrix in R is atomic (homogeneous). That is all the elements of the matrix must be of same mode (logical, numeric, complex or character).

matrix in R
matrix in R

Learn more about matrix in R in my tutorial about Matrix in R.

Arrays in R

Arrays in R is an atomic (homogeneous) data structure. Matrix is two dimensional object. When there are more than two dimensions, we use array to store such a data. Thus arrays are similar to matrices, but have more than two dimensions.

arrays in R
arrays in R

Learn more about arrays in R in my tutorial about Arrays in R.

Data Frames in R

In R language, a data frame is a primary data structure for handling tabular data sets like a spreadsheet. Data frames is an atomic data structure in R. Data frames are like matrices except that the columns are allowed to be of different types, i.e., data frames stores heterogeneous data types whereas matrix stores homogeneous data types.

data frames in R
data frames in R

Learn more about data frames in R in my tutorial about Data Frames in R.

Lists in R

Lists are the more general class of data storage. Lists are generic vectors where each element can be any type of object; e.g., a vector (of any mode), a matrix, a data frame or a function. Because of this flexibility, lists are the basis for most complex objects in R.

lists in R
lists in R

Learn more about lists in R in my tutorial about lists in R.


In this tutorial you learned about what are different data structures in R.

To learn more about other data structures in R, please refer to the following tutorials:

Hopefully you enjoyed learning this tutorial on data structures in R. Hope the content is more than sufficient to understand what is data structure in R.

VRCBuzz co-founder and passionate about making every day the greatest day of life. Raju is nerd at heart with a background in Statistics. Raju looks after overseeing day to day operations as well as focusing on strategic planning and growth of VRCBuzz products and services. Raju has more than 25 years of experience in Teaching fields. He gain energy by helping people to reach their goal and motivate to align to their passion. Raju holds a Ph.D. degree in Statistics. Raju loves to spend his leisure time on reading and implementing AI and machine learning concepts using statistical models.

Leave a Comment