Dplyr: full_join()

Hi all,

I have a piece of code which combined two data frames (df1 and df2) with the same columns, but different rows. Both have the same three columns (the first which is called "names" and for sake of argument the other two columns are c1 and c2) and both can have any number of rows. The values in the column "names" are all different between the data frames:

full_join(df1, df2, BY = names)

In the previous version of dplyr, by using this piece of code the second data frame was simply appended underneath the first and the resulting data frame would still be 3 columns and the number of rows would be the sum of the number of rows of the two data frames.

In the new version of dplyr, the function full_join has changed and I had to amend the code for it to work:

full_join(df1, df2, by = join_by(names))

However this doesn't result in the same data frame I used to get, but instead it returns two extra columns (the number of rows stays the same):

names, c1.x, c2.x, c1.y, c2.y

Does anyone have any idea how I can use this function to give me the previous result:

names, c1, c2

Kind regards,
Thijs

Why full_join() when columns are identical rather than just rbind(df1,df2) ? This of joins as adding vertical blocks with one common column and some number of different columns.

Thanks for the advice. I did manage to solve the problem by putting all columns in the join_by statement.

1 Like

In the new version of dplyr, the function full_join has changed and I had to amend the code for it to work:

To be clear, you should not have to change your existing full_join() code. It should still "just work" with a character vector of names.

Well it did not. I got an error message and the script broke down at that point. But after changing it to:

full_join(df1, df2, by = join_by(names, c1, c2))

it now works as it did before.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.