Arrays

In this lesson, we will learn what arrays are in R and how to create them.

Both data structures (vectors and lists) are one dimensional meaning they have only length and no other dimension.

On the plus side, arrays in R language can be n-dimensional. However, like vectors, arrays can store only values having the same data type.

Creating Arrays

In R, arrays can be created using the array() keyword. Inputs to array() include concatenated vectors and the dim argument for creating an array.

Syntax for Creating Arrays

array(<dataVectors>, dim = <vectorOfDimensions>)

Optionally, we can also provide names for each dimension!

Let’s begin with making a simple two-dimensional array with one vector.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy