title: Merge data frames and overwrite values
body: <p>How do I merge 2 similar data frames but have one with greater importance?</p>
  
  <p>For example:</p>
  
  <p>Dataframe 1</p>
  
  <pre><code>Date      Col1    Col2
  jan         2      1
  feb         4      2
  march       6      3
  april       8      NA
  </code></pre>
  
  <p>Dataframe 2</p>
  
  <pre><code>Date      Col2    Col3
  jan         9      10
  feb         8      20
  march       7      30
  april       6      40
  </code></pre>
  
  <p>merge these by Date with dataframe 1 taking precedence but dataframe 2 filling blanks</p>
  
  <p>DataframeMerge</p>
  
  <pre><code>Date      Col1    Col2    Col3
  jan         2       1      10
  feb         4       2      20
  march       6       3      30
  april       8       6      40
  </code></pre>
  
  <p>EDIT - SOLUTION</p>
  
  <pre><code>commonNames &lt;- names(df1)[which(colnames(df1) %in% colnames(df2))]
  commonNames &lt;- commonNames[commonNames != "key"]
  dfmerge&lt;- merge(df1,df2,by="key",all=T)
  for(i in commonNames){
    left &lt;- paste(i, ".x", sep="")
    right &lt;- paste(i, ".y", sep="")
    dfmerge[is.na(dfmerge[left]),left] &lt;- dfmerge[is.na(dfmerge[left]),right]
    dfmerge[right]&lt;- NULL
    colnames(dfmerge)[colnames(dfmerge) == left] &lt;- i
  }
  </code></pre>