Click to show/hide code
A <- matrix(c(2, 0, 5, 9), # element values
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
A[2, 1][1] 5