matrix %in% matrix

后端 未结 5 907
北恋
北恋 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:44

    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
    

提交回复
热议问题