Go to the RMD, R, PDF, or HTML version of this file. Go back to fan’s REconTools Package, R Code Examples Repository (bookdown site), or Intro Stats with R Repository (bookdown site).
Multiply Together a 3 by 2 matrix and a 2 by 1 vector
ar_row_one <- c(-1,+1)
ar_row_two <- c(-3,-2)
ar_row_three <- c(0.35,0.75)
mt_n_by_2 <- rbind(ar_row_one, ar_row_two, ar_row_three)
ar_row_four <- c(3,4)
# Matrix Multiplication
mt_out <- mt_n_by_2 %*% ar_row_four
print(mt_n_by_2)
## [,1] [,2]
## ar_row_one -1.00 1.00
## ar_row_two -3.00 -2.00
## ar_row_three 0.35 0.75
print(ar_row_four)
## [1] 3 4
print(mt_out)
## [,1]
## ar_row_one 1.00
## ar_row_two -17.00
## ar_row_three 4.05