Load data in the workspace by executing:

source("http://www3.nd.edu/~steve/computing_with_data_2014/4_Matrices/work_along_data_S4.R")

Matrix formation and arrangement

How many rows and columns are in M1?

nrow(M1)
## [1] 2
ncol(M1)
## [1] 6

Rearrange the underlying entries of M1 as a 4 x 3 matrix.

M1_New <- matrix(M1, nrow=4, ncol=3)
M1_New
##      [,1] [,2] [,3]
## [1,]    1    5    9
## [2,]    2    6   10
## [3,]    3    7   11
## [4,]    4    8   12

Subsetting and assignment

Replace the NA values in M2 by 0’s

M2[is.na(M2)] <- 0
M2
##      [,1] [,2] [,3] [,4] [,5]
## [1,]    1    0    9   13   17
## [2,]    2    6   10    0   18
## [3,]    3    7   11   15    0
## [4,]    4    8   12   16   20

rbind and cbind

Form a matrix that binds the columns of M1 and the matrix z. Check that the dimensions match first.

dim(M1)
## [1] 2 6
dim(z)
## [1] 2 2

Since the dimensions match, we may form a matrix as described above.

MM1<-cbind(M1,z)
MM1
##      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] "1"  "3"  "5"  "7"  "9"  "11" "a"  "a" 
## [2,] "2"  "4"  "6"  "8"  "10" "12" "a"  "a"

What happened to the numbers?

The number were converted into characters due to the mixture of numeric and character entries.