Can I replace NAs when joining two data frames with dplyr?
<p>I would like to join two data frames. Some of the column names overlap, and there are <code>NA</code> entries in one of the data frame's overlapping columns. Here is a simplified example:</p>
<pre><code>df1 &lt;- data.frame(fruit = c('apples','oranges','bananas','grapes'), var1 = c(1,2,3,4), var2 = c(3,NA,6,NA), stringsAsFactors = FALSE)
df2 &lt;- data.frame(fruit = c('oranges','grapes'), var2=c(5,6), var3=c(7,8), stringsAsFactors = FALSE)
</code></pre>
<p>Can I use dplyr join functions to join these data frames and automatically prioritize the non-<code>NA</code> entry so that I get the &quot;var2&quot; column to have no <code>NA</code> entries in the joined data frame? As it is now, if I call <code>left_join</code>, it keeps the <code>NA</code> entries, and if I call <code>full_join</code> it duplicates the rows.</p>
<p><strong>Example Data</strong></p>
<pre><code>&gt; df1
    fruit var1 var2
1  apples    1    3
2 oranges    2   NA
3 bananas    3    6
4  grapes    4   NA
&gt; df2
    fruit var2 var3
1 oranges    5    7
2  grapes    6    8
</code></pre>