如何确定与特定行名称对应的行索引号?我有一个行名称向量,我想使用这些向量来获得矩阵中相应行索引的向量。我尝试了row()和as.integer(rownames(matrix.object)),但似乎都不起作用。
row()
as.integer(rownames(matrix.object))
ctzwtxfj1#
除了which之外,您还可以查看match:
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
5jdjgkvh2#
尝试which:
which(rownames(matrix.object) %in% c("foo", "bar"))
2条答案
按热度按时间ctzwtxfj1#
除了
which
之外,您还可以查看match
:5jdjgkvh2#
尝试
which
: