matrix %in% matrix

r

Solution

Another approach would be:

> paste(a[,1], a[,2], sep="$$") %in% paste(x[,1], x[,2], sep="$$")
[1] FALSE  TRUE  TRUE FALSE

A more general version of this is:

> apply(a, 1, paste, collapse="$$") %in% apply(x, 1, paste, collapse="$$")
[1] FALSE  TRUE  TRUE FALSE

Problem

Suppose I have two matrices, each with two columns and differing numbers of row. I want to check and see which pairs of one matrix are in the other matrix. If these were one-dimensional, I would normally just do `a %in% x` to get my results. `match` seems only to work on vectors. ``` > a [,1] [,2] [1,] 1 2 [2,] 4 9 [3,] 1 6 [4,] 7 7 > x [,1] [,2] [1,] 1 6 [2,] 2 7 [3,] 3 8 [4,] 4 9 [5,] 5 10 ``` I would like the result to be `c(FALSE,TRUE,TRUE,FALSE)`.

Original source

Related problems