title: Partial merge in R
body: <p>Before I end up at -7 like <a href="https://stackoverflow.com/questions/12123013/two-by-two-matching-between-dataframes-in-r">Two by two matching between dataframes in r</a> did, let me say I've already read the following pages:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/10013985/how-to-copy-row-from-one-data-frame-in-to-another-r">How to copy row from one data.frame in to another [R]</a></li>
  <li><a href="https://stackoverflow.com/questions/12427043/r-how-to-update-a-column-in-data-frame-using-values-from-another-data-frame">R How to update a column in data.frame using values from another data.frame</a></li>
  <li><a href="https://stackoverflow.com/questions/7971513/using-one-data-frame-to-update-another?rq=1">Using one data.frame to update another</a></li>
  </ul>
  
  <p>Actually, the last one is really similar to what I want, but not the same, because my columns are different</p>
  
  <p>I have two dataframes, let's say:</p>
  
  <pre><code>&gt; d &lt;- data.frame(year=c(2004,2004,2006),month = c(1,5,3), height = c(1000,2000,3000) )
  &gt; d
    year month height
  1 2004     1   1000
  2 2004     5   2000
  3 2006     3   3000
  
  &gt; e &lt;- data.frame(year=c(2004),month=c(5), height = c(9999))
  &gt; e
    year month height
  1 2004     5   9999
  </code></pre>
  
  <p>Obviously the real data is longer than this.</p>
  
  <p>I want to merge the values from e into d</p>
  
  <p>Try raw merge:</p>
  
  <pre><code>&gt; merge(d,e)
  [1] year   month  height
  &lt;0 rows&gt; (or 0-length row.names)
  </code></pre>
  
  <p>Ok.  So add "by":</p>
  
  <pre><code>&gt; merge(d,e,by=c("year","month"))
    year month height.x height.y
  1 2004     5     2000     9999
  </code></pre>
  
  <p>Ok, it did an inner join, and got rid of all the original data in d.  So try left outer join:</p>
  
  <pre><code>&gt; merge(d,e,by=c("year","month"),all.x = T)
    year month height.x height.y
  1 2004     1     1000       NA
  2 2004     5     2000     9999
  3 2006     3     3000       NA
  </code></pre>
  
  <p>It did a join, and it's correct as per outer-join definition, but it didn't do what I want, which is to update the values in d from the values in e.  What I really want is more like an sql update:</p>
  
  <pre><code>for (year,month,height) in e:
      update d set d.height=e.height where d.year = e.year and d.month = e.month
  </code></pre>
  
  <p>ie the results I want would be:</p>
  
  <pre><code>&gt; magic(d,e)
    year month height
  1 2004     1   1000
  2 2004     5   9999
  3 2006     3   3000
  </code></pre>
  
  <p>Of course, I could just write a bunch of <code>for</code> loops, but I'm hoping there is some vectorized way of doing this?</p>
  
  <p>Edit: my example had only one key column, but my real problem has two.  Updated the example to reflect this.</p>