Can dplyr join on multiple columns or composite key?

后端 未结 1 1348
遥遥无期
遥遥无期 2020-11-28 19:50

I realize that dplyr v3.0 allows you to join on different variables:

left_join(x, y, by = c(\"a\" = \"b\") will match x.a to <

相关标签:
1条回答
  • 2020-11-28 20:45

    Updating to use tibble()

    You can pass a named vector of length greater than 1 to the by argument of left_join():

    library(dplyr)
    
    d1 <- tibble(
      x = letters[1:3],
      y = LETTERS[1:3],
      a = rnorm(3)
      )
    
    d2 <- tibble(
      x2 = letters[3:1],
      y2 = LETTERS[3:1],
      b = rnorm(3)
      )
    
    left_join(d1, d2, by = c("x" = "x2", "y" = "y2"))
    
    0 讨论(0)
提交回复
热议问题