Page 236 - Data Science class 11
P. 236
After the execution of the above code, the following result will be displayed:
6.10.3 manipulating array elements
As an array is made up of matrices in multiple dimensions, the operations on the elements of the array are carried out
by accessing elements of the matrices.
Example
Enter the following code snippet:
# Creating two vectors of different lengths.
vector1 <- c(4,8,3)
vector2 <- c(11,12,13,14,15,16)
# Take these vectors as input to the array.
array1 <- array(c(vector1,vector2),dim = c(3,3,2))
# Creating another two vectors of different lengths.
vector3 <- c(9,1,0)
vector4 <- c(6,0,11,3,14,1,2,6,9)
array2 <- array(c(vector1,vector2),dim = c(3,3,2))
# create matrices from these arrays.
matrix1 <- array1[,,2]
matrix2 <- array2[,,2]
# Add the matrices.
result <- matrix1+matrix2
print(result)
234 Touchpad Data Science-XI

