13) Selecting from a Matrix.

This Blog entry is from the Data Structures section in Learn R.

As a matrix is made up of vectors, it is logical to expect it to bear some resemblance in the way selection from a matrix takes place.   All subscripting in a separate dimension when specified inside the [] square brackets, as separate arguments.  The first argument inside the square brackets relates to the row, the next the column.

To obtain the value in a given position of a matrix, in this case two down, three across, type:

OverspillMatrix[2,3]
selecting-a-variable-from-a-matrix-in-r.png

Run the line of script to console:

selecting-a-variable-from-a-matrix-written-to-r-console.png

It can be seen that the value 2 has been returned which corresponds to the position specified:

a-validation-of-the-value-returned-from-the-matrix-in-r-console.png