How to Apply the row() Function in R (Example Code)

In this tutorial, I’ll show how to return row indices and labels using the row() function in the R programming language.

Creation of Example Data

x <- matrix(10:18, nrow = 3)    # Construct matrix object in R
x
#      [,1] [,2] [,3]
# [1,]   10   13   16
# [2,]   11   14   17
# [3,]   12   15   18

Example: Return Row Indices of Matrix Using row() Function

row(x)                          # Print row indices
#      [,1] [,2] [,3]
# [1,]    1    1    1
# [2,]    2    2    2
# [3,]    3    3    3

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top