如何获取特定名称的行索引号?

编程入门 行业动态 更新时间:2024-10-15 10:17:13
本文介绍了如何获取特定名称的行索引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

如何获取特定名称的行索引号?

本文发布于:2023-11-30 13:59:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:索引   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!