Contents

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

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.

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).

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.

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*.

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.

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

## Endnote

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:

- Data Types in R
- Variables and Constants in R
- Vectors in R
- Matrix in R
- List in R
- Factors in R
- Data Frames in R

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.