R How to Find the Refferencing Row Index Number (Example Code)
In this post, I’ll show how to identify the row index number in a data frame in the R programming language.
Creation of Exemplifying Data
data(iris) # Loading and modifying iris data set.seed(982734) rownames(iris) <- sample(1:nrow(iris)) head(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 83 5.1 3.5 1.4 0.2 setosa # 82 4.9 3.0 1.4 0.2 setosa # 101 4.7 3.2 1.3 0.2 setosa # 57 4.6 3.1 1.5 0.2 setosa # 10 5.0 3.6 1.4 0.2 setosa # 132 5.4 3.9 1.7 0.4 setosa |
data(iris) # Loading and modifying iris data set.seed(982734) rownames(iris) <- sample(1:nrow(iris)) head(iris) # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 83 5.1 3.5 1.4 0.2 setosa # 82 4.9 3.0 1.4 0.2 setosa # 101 4.7 3.2 1.3 0.2 setosa # 57 4.6 3.1 1.5 0.2 setosa # 10 5.0 3.6 1.4 0.2 setosa # 132 5.4 3.9 1.7 0.4 setosa
Example: Using which & rownames to Find Row Index Number of Data Frame
which(rownames(iris) == 57) # which & rownames functions # 4 |
which(rownames(iris) == 57) # which & rownames functions # 4