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!
duplicatedwould also return any rows that get repeated within a matrix, even if it appears in only one of the two matrices. Anyway, @MatthewDowle's answer is great. - David Robinsondata.tablemight be faster because it doesn't usedo.call("paste"under the hood. If you preferduplicatedtoM2[M1]thenduplicated(as.data.table(rbind(m1,m2)))might be faster, for the same reason. Interested to see your timings. - Matt Dowleduplicatedapproach. - Matt Dowle