matrix %in% matrix

后端 未结 5 906
北恋
北恋 2020-12-08 23:24

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

5条回答
  •  北海茫月
    2020-12-08 23:50

    Here is another approach using the digest package and creating checksums for each row, which are generated using a hashing algorithm (the default being md5)

    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)
    apply(a, 1, digest) %in% apply(x, 1, digest)
    
    [1] FALSE  TRUE  TRUE FALSE
    

提交回复
热议问题