如何获取特定名称的行索引号? [英] How to get row index number for particular name(s)?

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

问题描述

如何确定特定行名称对应的行索引号?我有一个行名称向量,我想使用它们来获取矩阵中相应行索引的向量.

How can one determine the row index-numbers corresponding to particular row names? I have a vector of row names, and I would like to use these to obtain a vector of the corresponding row indices in a matrix.

我尝试了 row()as.integer(rownames(matrix.object)),但似乎都不起作用.

I tried row() and as.integer(rownames(matrix.object)), but neither seems to work.

推荐答案

除了which,还可以看match:

m <- matrix(1:25, ncol = 5, dimnames = list(letters[1:5], LETTERS[1:5]))
vec <- c("e", "a", "c")
match(vec, rownames(m))
# [1] 5 1 3

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

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