dplyr可以join多个列或组合键吗?

我意识到dplyr v3.0允许你join不同的variables:

left_join(x, y, by = c("a" = "b")将匹配xayb

但是,是否有可能joinvariables的组合? 或者我必须提前添加一个复合键?

这就像是:

left_join(x, y, by = c("ac" = "bd")以匹配[ xaxc ]到[ ybyd ]的级联

您可以传递一个长度大于1的命名向量给left_join()by参数:

 library(dplyr) d1 <- data_frame( x = letters[1:3], y = LETTERS[1:3], a = rnorm(3) ) d2 <- data_frame( x2 = letters[3:1], y2 = LETTERS[3:1], b = rnorm(3) ) left_join(d1, d2, by = c("x" = "x2", "y" = "y2"))