How to get row index number in R?

前端 未结 6 1216
无人共我
无人共我 2021-01-31 13:46

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.

6条回答
  •  借酒劲吻你
    2021-01-31 14:15

    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.

提交回复
热议问题