簡體   English   中英

當矩陣的兩列與 r 中的給定值匹配時,如何找到矩陣的行號

[英]How to find the row number of a matrix when its two columns match the given values in r

我有一個 4X5 矩陣示例:

a = 1 2 3 4 5
    2 3 3 4 1
    5 6 77 8 9
    10 9 3 4 17

在這里,我想知道a[,3] == 3a[,4] == 4的行號。 我想得到的答案是 1,2 和 4 How do I get it in r

用這個

a = matrix(c(1,2,3,4,5,2,3,3,4,1,5,6,77,8,9,10,9,3,4,17), byrow = T, ncol = 5)
which(a[, 3] == 3 & a[ ,4] == 4)

[1] 1 2 4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM