Arrays
Arrays
Arrays are similar to matrices but can have more than two dimensions.
Where vector contains the data for the array, dimensions is a numeric vector giving the
maximal index for each dimension, and dimnames is an optional list of dimension labels
Three-dimensional (2x3x4) array of numbers
As you can see, arrays are a natural extension of matrices. They can be
useful in programming new statistical methods. Like matrices, they must
be a single mode.
Array_Name[row_position, Column_Position,
Matrix_Level].
Functions -Array
is.array()
Check for array if the object is an array or not. The function
name is.array() is a primitive function that lets you do so. Its
gives output in terms True or False
The function applied is also base for other complex functions like lapply(), rapply(), etc.
Addition & Subtraction
•Addition:
vector1 <- c(2,18,30)
vector2 <- c(10,14,17,13,11,15,22,11,33)
column.names <-
c("COL1","COL2","COL3","COL4")
row.names <- c("ROW1","ROW2","ROW3")
matrix.names <- c("Matrix1","Matrix2")
result <- array(c(vector1,vector2),dim =
c(3,4,2),dimnames =
list(row.names,column.names,
matrix.names))
result[,,1] result[,,2] print(result[,,1] +
result[,,2])
•Subtraction: