Is there a fast way of finding which rows in matrix A are present in matrix B? e.g.
m1 = matrix(c(1:6), ncol=2, byrow = T); m2 = matrix(c(1:4), ncol=2, byrow=T);
and the result would be 1, 2.
The matrices do not have the same number of rows (number of columns is the same), and they are somewhat big - from 10^6 - 10^7 number of rows.
The fastest way of doing it, that I know of for now, is:
duplicated(rbind(m1, m2))
Tnx!
A fast way for that size should be :
require(data.table)
M1 = setkey(data.table(m1))
M2 = setkey(data.table(m2))
na.omit(
M2[M1,which=TRUE]
)
[1] 1 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With