3

This is a really simple question, but can't find a suitable answer here.

How does one join two data.frames with dplyr based on two columns with different names in each data.frame?

With base::merge one can simply merge:

df3 <- merge(df1, df2, by.x=c("name1", "name2"), by.y=c("name3", "name4"))

where df1$name1 == df2$name3 and df1$name2 == df2$name4.

How does one do this in dplyr?


I know that one can use the by function in dplyr to do join two data.frames with based on one column with a different name:

df3 <- dplyr::left_join(df1, df2, by=c("name1" = "name3"))
2

1 Answer 1

18
df3 <- dplyr::left_join(df1, df2, by=c("name1" = "name3", "name2" = "name4"))
Sign up to request clarification or add additional context in comments.

1 Comment

Does this work also with autobox?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.