[英]How to find the number of columns of an R matrix that contains values greater than or equal to a given number?
[英]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] == 3
和a[,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.