You can use inner_join()
function from dplyr
package:
df1 <- data.frame(x = c(-7.47, -8.88, -6.32, -5.44, -4.21, -3.11, -2.56, -9.21, -8.33, -11.11),
y = c(5.88, 4.55, 3.33, 2.33, 1.22, 9.11, 10.12, 6.32, 2.44, 5.55),
z = c(200, 123, 233, 133, 433, 111, 453, 325, 712, 333))
df2 <- data.frame(x = c(-7.47, -3.11, -8.33, -9.21),
y = c(5.88, 9.11, 2.44, 6.32))
library(dplyr)
inner_join(df1, df2)
Joining, by = c("x", "y")
x y z
1 -7.47 5.88 200
2 -3.11 9.11 111
3 -9.21 6.32 325
4 -8.33 2.44 712
If you want to do this without using dplyr
:
df1[(df1$x %in% df2$x) & (df1$y %in% df2$y), ]
NOTE: Please provide a reproducible data example next time. You should have defined df1
and df2
as in my answer and not let me do it.