I would like to merge two dataframes. There are some shared variables and some different variables and there are different numbers of rows in each dataframe. The dataframes share some rows, but not all. And both dataframes have missing data that the other my have.
DF1:
| name | age | weight | height |
|---|---|---|---|
| Tim | 7 | 54 | 112 |
| Dave | 5 | 50 | NA |
| Larry | NA | 42 | 73 |
| Rob | 1 | 30 | 43 |
DF2:
| name | age | weight | height | grade |
|---|---|---|---|---|
| Tim | 7 | NA | 112 | 2 |
| Dave | NA | 50 | 103 | 1 |
| Larry | 3 | NA | 73 | NA |
| Rob | 1 | 30 | NA | NA |
| John | 6 | 60 | NA | 1 |
| Tom | 8 | 61 | 112 | 2 |
I want to merge these two dataframes together by the shared columns (name, age, weight, and height). However, I want NAs to be overridden, such that if one of the two dataframes has a value where the other has NA, I want the value to be carried through into the third dataframe. Ideally, the last dataframe should only have NAs when both DF1 and DF2 had NAs in that same location.
Ideal Data Frame
| name | age | weight | height | grade |
|---|---|---|---|---|
| Tim | 7 | 54 | 112 | 2 |
| Dave | 5 | 50 | 103 | 1 |
| Larry | 3 | 42 | 73 | NA |
| Rob | 1 | 30 | 43 | NA |
| John | 6 | 60 | NA | 1 |
| Tom | 8 | 61 | 112 | 2 |
I've been using full_join and left_join, but I don't know how to merge these in such a way that NAs are replaced with actual data (if it is present in one of the dataframes). Is there a way to do this?