How to specify names of columns for x and y when joining in dplyr? How to specify names of columns for x and y when joining in dplyr? r r

How to specify names of columns for x and y when joining in dplyr?


This feature has been added in dplyr v0.3. You can now pass a named character vector to the by argument in left_join (and other joining functions) to specify which columns to join on in each data frame. With the example given in the original question, the code would be:

left_join(test_data, kantrowitz, by = c("first_name" = "name"))


This is more a workaround than a real solution. You can create a new object test_data with another column name:

left_join("names<-"(test_data, "name"), kantrowitz, by = "name")     name gender1    john      M2    bill either3 madison      M4    abby either5     zzz   <NA>