I have two sets: A with columns x, y and B also with columns x, y. I need to find the index of the rows A that are inside B (both x and y must match). I came up with a simple solution (see below), but this comparison is inside the loop, and paste
adds a lot more extra time.
B <- data.frame(x = sample(1:1000, 1000), y = sample(1:1000, 1000)) A <- B[sample(1:1000, 10),]
For example, for one observation, the paste
alternative is almost 3 times faster
ind <- sample(1:1000, 1) xx <- B$x[ind] yy <- B$y[ind] ind <- which(with(B, x==xx & y==yy))
source share