How to conditionally combine data.frame object in the list in more elegant way?
<p>I have data.frame in the list, and I intend to merge specific data.frame objects conditionally where merge second, third data.frame objects without duplication, then merge it with first data.frame objects. However, I used rbind function to do this task, but my approach is not elegant. Can anyone help me out the improve the solution ? How can I achieve more compatible solution that can be used in dynamic functional programming ? How can I get desired output ? Any idea ? </p>

<p>reproducible example:</p>

<pre><code>dfList &lt;- list(
  DF.1 = data.frame(red=c(1,2,3), blue=c(NA,1,2), green=c(1,1,2)),
  DF.2 = data.frame(red=c(2,3,NA), blue=c(1,2,3), green=c(1,2,4)),
  DF.3 = data.frame(red=c(2,3,NA,NA), blue=c(1,2,NA,3), green=c(1,2,3,4))
)
</code></pre>

<p>dummy way to do it:</p>

<pre><code>rbind(dfList[[1L]], unique(rbind(dfList[[2L]], dfList[[3L]])))
</code></pre>

<p>Apparently, my attempt is not elegant to apply in functional programming. How can make this happen elegantly ?</p>

<p>desired output :</p>

<pre><code>red blue green
1    1   NA     1
2    2    1     1
3    3    2     2
11   2    1     1
21   3    2     2
31  NA    3     4
6   NA   NA     3
</code></pre>

<p>How can I improve my solution more elegantly and efficiently ? Thanks in advance</p>