Solution Review: Arrays and Matrices

In this review, we give a detailed analysis of the solution to this problem.

Solution #1: Using 33 vectors

Press + to interact
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 11 because we want just one matrix.

Solution #2: Using 11 vector

Press + to interact
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 3x33x3 matrix.