Dplyr allows us to join two data frames on more than a single column. All you have to do is to add the columns within the by
like by = c("x1" = "x2", "y1" = "y2")
. For example:
library(dplyr) set.seed(5) df1 <- tibble( x1 = letters[1:10], y1 = LETTERS[11:20], a = rnorm(10) ) df2 <- tibble( x2 = letters[1:10], y2 = LETTERS[11:20], b = rnorm(10) ) df<-df1%>%inner_join(df2, df2, by = c("x1" = "x2", "y1" = "y2")) df
# A tibble: 10 x 4
x1 y1 a b
<chr> <chr> <dbl> <dbl>
1 a K -0.841 1.23
2 b L 1.38 -0.802
3 c M -1.26 -1.08
4 d N 0.0701 -0.158
5 e O 1.71 -1.07
6 f P -0.603 -0.139
7 g Q -0.472 -0.597
8 h R -0.635 -2.18
9 i S -0.286 0.241
10 j T 0.138 -0.259