Comparing rows between two matrices
matrix, r
Solution
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
Problem
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!