i

R Programming Complete Tutorial

Access Matrix elements

Access element by position (index):

We can access any matrix element using the corresponding index. We have to use an expression like mat1 [m, n], where mat1 is the name of the Matrix, m is the row position, and n is the column position. For the first example, we use mat1 [2, 3], so it will go to the second position of the Matrix then select the 3rd column. For this specific example, it will return 6.  

We have mentioned more examples in the below section:

Access the elements by names:

We can also select the matrix element by its corresponding row and column name.