My aim is to find row indices of a matrix (dat) that contain matching rows of another matrix (xy).
I find it easy to do this with smaller matrices, as shown in the examples. But the matrices I have a very large number of rows.
For toy example the matrices dat and xy are given below. The aim is to recover the indices 14, 58, 99. In my case, both these matrices have a very larger number of rows.
# toy data
dat <- iris
dat$Sepal.Length <- dat$Sepal.Length * (1 + runif(150))
xy <- dat[c(14, 58, 99), c(1, 5)]
For small matrices, the solutions would be
# solution 1
ind <- NULL
for(j in 1 : length(x)) {
ind[j] <- which((dat$Sepal.Length ==xy[j, 1]) & (dat$Species == xy[j, 2]))
}
Or
# solution 2
which(outer(dat$Sepal.Length, xy[, 1], "==") &
outer(dat$Species, xy[, 2], "=="), arr.ind=TRUE)
But given the size of my data, these methods are not feasible. The first method takes a lot of time and the other fails due to lack of memory.
I wish I know more data.table and dplyr.