Solution Review: Arrays and Matrices
In this review, we give a detailed analysis of the solution to this problem.
We'll cover the following
Solution #1: Using vectors
myVector1 <- c ('a', 'b', 'c')myVector2 <- c ('d', 'e', 'f')myVector3 <- c ('g', 'h', 'i')myArray <- array (c(myVector1, myVector2, myVector3), dim = c(3, 3, 1))cat(myArray)
Explanation
Simply make three vectors and pass them to array()
. Also, set the specific dimensions. Notice that the last argument to dim
is because we want just one matrix.
Solution #2: Using vector
myVector <- c ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i')myArray <- array (myVector, dim = c(3, 3, 1))cat(myArray)
Explanation
We can also use only one vector, populate it, and pass it to array()
. However, the dim
argument remains the same because we want one matrix.