3. Objects that contain an array

An array is nothing more than a matrix with more than two dimensions. It is basically a series of two-dimensional matrices “on top of each other”; in other words, a matrix is an array with only two dimensions, or only one layer. To build an array, there is a function called… array(), and inside that function, you’ll need to use the option dim (dimension) to organize the number of rows, columns… and layers. In the following example, we build an array called long.box made of 4 rows, 3 columns and 2 layers, and containing the values ranging from 1 to 24:

[code language=”r”]
long.box <- array(1:24, dim=c(4,3,2))

long.box array

As seen on the picture above, we obtain 2 matrices each containing 12 values arranged in 4 rows and 3 columns. Each matrix or layer of the array is identify by its “layer number” following 2 commas  , , 1 and  , , 2. Logically, the first layer contains data ranging from 1 to 12 and the second layer contains values from 13 to 24.



  Fant du det du lette etter? Did you find this helpful?
[Average: 0]