Array is a type of object or data structure in R-language. They are designed to store values of same data-type in multiple dimensions. For example, if you wish to create an array of dimensions (3,5,4), then it will return 4 arrays each having 3 rows and 5 columns.
This recipe demonstrates how to create an array based on a specific dimension using 2 vectors.
We create 2 different sized vectors using c() function
a = c(2,4,6,8,10,12,14) b = c(3,6,9,12,15,18,21,24,27)
We use array() function to create an array in R-language.
Syntax: array(data, dim, dim_names)
We now use this function to create an array with 2 rows, 3 columns and 1 array count from 2 vectors. i.e. dimension = (2,3,1)
array_ = array(c(a,b), dim = c(2,3,1)) print(array_)
, , 1 [,1] [,2] [,3] [1,] 2 6 10 [2,] 4 8 12