Get element at the specific position from matrix in R
At any point in time, a matrix may be required to be traversed for an element at a specific position. In this article, we are going to access the elements from a matrix in R Programming Language using integer vector, logical vector as the index.
Method 1: Accessing elements using integer vector
Integer vector is a vector, that includes all elements of integer type.
select rows 1 & 3 and columns 1 & 3 of matrix a.
Method 2: Accessing matrix elements using logic vector
Logical vector includes a vector comprising boolean values i.e. TRUE or FALSE.
If TRUE at that position, matrix element is accessed
If FALSE at that position, matrix element is not accessed.