[R] Intersecting two matrices

c char
Mon, 29 Jul 2013 23:04:11 -0000

Dear all,

I am interested to know a faster matrix intersection package for R handles
intersection of two integer matrices with ncol=2. Currently I am using my
homemade code adapted from a previous thread:


intersectMat <- function(mat1, mat2){#mat1 and mat2 are both
deduplicated  nr1 <- nrow(mat1)  nr2 <- nrow(mat2)
mat2[duplicated(rbind(mat1, mat2))[(nr1 + 1):(nr1 + nr2)], ]}


which handles:
size A= 10578373
size B= 9519807
expected intersecting time= 251.2272
intersecting for corssing MPRs took 409.602 seconds.

scale a little bit worse than linearly but atomic operation is not good.
Wonder if a super fast C/C++ extension exists for this task. Your ideas are
appreciated.

Thanks!

	[[alternative HTML version deleted]]