Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何确定与特定行名对应的行索引号?我有一个行名向量,我想用这些来获取矩阵中相应行索引的向量。
我试过row()and as.integer(rownames(matrix.object)),但似乎都不管用。
row()
as.integer(rownames(matrix.object))
除此之外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
尝试which:
which(rownames(matrix.object) %in% c("foo", "bar"))