Difference between Array and Matrix in R

Array and Matrix in R:

These two notions are generalizations of the vector notion: they represent sequences with two indices for matrices and with multiple indices for arrays. As with vectors, elements must be of the same type, otherwise implicit conversions will occur. It has the following instruction:

[matlab]> X <- matrix(1:12,nrow=4,ncol=3,byrow=TRUE) > X
[/matlab]

Difference between Array and Matrix in R

Output:
[matlab]
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[4,] 10 11 12
[/matlab]

The function array() is used to create multidimensional matrices with more than two dimensions,
Example:
[matlab]> X <- array(1:12,dim=c(2,2,3)) > X
, , 1
[,1] [,2]
[1,] 1 3
[2,] 2 4
, , 2
[,1] [,2]
[1,] 5 7
[2,] 6 8
, , 3
[,1] [,2]
[1,] 9 11
[2,] 10 12
> class(X)
[1] “array”
[/matlab]