my_size <- 3
M_identity <- matrix(0, 
                     nrow = my_size, 
                     ncol = my_size)

# solution
diag(M_identity) <- 1

print(M_identity)

Question

Wihtin an R session, create an identity matrix (value 1 in the diagonal, zero in any other) of size 3X3. Tip: use the diag function to define the diagonal of the matrix.

Solution


Meta-information

extype: string exsolution: r mchoice2string(c(TRUE, FALSE, FALSE, FALSE, FALSE), single = TRUE) exname: "matrix" exshuffle: TRUE



msperlin/afedR documentation built on Sept. 11, 2022, 9:49 a.m.