如何获取R中的行索引号? [英] How to get row index number in R?

查看:797
本文介绍了如何获取R中的行索引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在R中有一个列表或数据框架,我想得到行索引,我该如何做?也就是说,我想知道某个矩阵包含多少行。

解决方案

我将你的问题解释为关于获得行号。




  • 您可以尝试 as.numeric(rownames(df))不要设置rownames。否则使用序列 1:nrow(df)

  • which()函数将TRUE / FALSE行索引转换为行号。


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.

解决方案

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.

这篇关于如何获取R中的行索引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆