Ch1.3.1 Preactivity

R Commands, Slide 1 of 3

  • Open R Studio
  • Enter the command below to obtain the result shown.
(A <- matrix(1:6, nrow = 2, ncol = 3, byrow = TRUE))
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6

R Commands, Slide 2 of 3

  • Open R Studio
  • Enter the command below to obtain the result shown.
  • What is difference between this example and previous one?
(A <- matrix(1:6, nrow = 2, ncol = 3, byrow = FALSE))
     [,1] [,2] [,3]
[1,]    1    3    5
[2,]    2    4    6

R Commands, Slide 3 of 3

Next, enter these commands.

(A <- matrix(c(3, 5, 2, 3), nrow = 2, ncol = 2))
(B <- matrix(c(1, 1, 0, 1), nrow = 2, ncol = 2))
A %*% B
(C <- diag(c(1, 2, 3)))