How to get row index number in R?

dataframe, r

Solution

I'm interpreting your question to be about getting row numbers.

- You can try `as.numeric(rownames(df))` if you haven't set the rownames. Otherwise use a sequence of `1:nrow(df)`.

- The `which()` function converts a TRUE/FALSE row index into row numbers.

Problem

Suppose I have a list or data frame in R, and I would like to get the row index, how do I do that? That is, I would like to know how many rows a certain matrix consists of.

Original source