Click to show/hide code
<- matrix(c(2, 0, 5, 9), # element values
A nrow = 2, # specify the number of rows
byrow = TRUE) # fill the matrix by rows
A
[,1] [,2]
[1,] 2 0
[2,] 5 9
Click to show/hide code
# Any element can be extracted using the row and column index, For example, the element in the second row and first column (5) can be extracted from the matrix A as follows
2, 1] A[
[1] 5