VOOZH about

URL: https://www.geeksforgeeks.org/r-language/get-element-at-the-specific-position-from-matrix-in-r/

⇱ Get element at the specific position from matrix in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Get element at the specific position from matrix in R

Last Updated : 23 Jul, 2025

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, and logical vector as the index.

Accessing Elements in a Matrix

In R Programming Language we have several methods to Accessing Elements in a Matrix In R we can access matrix elements using square brackets [ ] notation.

Create a matrix

Output:

 [,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12

Accessing Single Element in a Matrix

Output:

 [,1] [,2] [,3] [,4]
[1,] 1 4 7 10
[2,] 2 5 8 11
[3,] 3 6 9 12[1] 4

Accessing Entire Row or Column

Output:

[1] 2 5 8 11[1] 7 8 9

Accessing Subsetting Matrix

Output:

 [,1] [,2]
[1,] 4 7
[2,] 5 8

Accessing matrix Conditional Access

Output:

[1] 6 7 8 9 10 11 12

These methods provide flexibility depending on our specific needs and the structure of our matrices. Choose the one that best fits our use case.

Comment

Explore