title: Matching rows in separate datasets based on multi-column indices in R
body: <p>I have two datasets with the same columns, but different values in the columns. I want to be able to perform an operation similar to <a href="http://www.exceltactics.com/vlookup-multiple-criteria-using-index-match/3/" rel="nofollow">"Index-match"</a> in Excel such that a row from one dataset matches up to it's equivalent row in the other so that I can perform operations on the lined up data.</p>
  
  <p>For example,</p>
  
  <pre><code>#create example dataframes
  d1 &lt;- data.frame(country = c('US','US','US','DE','DE'), 
              type = c('A','B','C','A','B'),
              val = c(1,6,3,3,7))
  
  d2 &lt;- data.frame(country = c('US','DE','US','BR','DE'), 
               type = c('B','C','A','B','C'),
               val = c(2,2,33,0,9))
  </code></pre>
  
  <p>I would like to match the rows in <code>d1</code> that correspond to <code>d2</code> and do <code>d1$val - d2$val</code> and save a new dataframe, <code>d3</code> that will be only the rows who's key columns matched.</p>
  
  <p>In this example, <code>d1[1,1:2]</code> matches <code>d2[3,1:2]</code> so they should line up,etc.</p>