Recreate your data:
a <- matrix(c(1, 2, 4, 9, 1, 6, 7, 7), ncol=2, byrow=TRUE)
x <- matrix(c(1, 6, 2, 7, 3, 8, 4, 9, 5, 10), ncol=2, byrow=TRUE)
Define a function %inm%
that is a matrix analogue to %in%
:
`%inm%` <- function(x, matrix){
test <- apply(matrix, 1, `==`, x)
any(apply(test, 2, all))
}
Apply this to your data:
apply(a, 1, `%inm%`, x)
[1] FALSE TRUE TRUE FALSE
To compare a single row:
a[1, ] %inm% x
[1] FALSE
a[2, ] %inm% x
[1] TRUE
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…