title: How can I merge two data frames with multiple common keys without duplicating rows in R?
body: <p>For instance, say I want to merge df1 and df2 (see below). Not only do they have different #s of rows but also different #s of columns. They also have multiple columns that repeat themselves, as well as values under the "Sales" column that repeat themselves. What I'd like to do is merge by "Sales" (don't want duplicate values under "Sales") and by "Date", "Price", and "SKU" (duplicate values under these columns are OK), and adding in the "PVC" column and filling any missing cells w/ NA values. Basically, here's the end product I want:</p>
  
  <pre><code>Date        Sales Price SKU   PVC
  2007/01/02   1     1.29 52648 Q
  2007/01/02   2     1.99 48721 N/A
  2007/01/02   5     0.55 65897 N/A
  2007/01/02   6     5.00 56482 N/A
  2007/01/02   10    2.50 46521 N/A
  2009/01/02   4     5.99 75677  Z
  </code></pre>
  
  <p>Doing this with:</p>
  
  <pre><code>merge(df1,df2,c("Date","Sales","Price","SKU"),all=TRUE)
  </code></pre>
  
  <p>does not work, because it gets rid of any rows that don't completely match on all 4 of those columns. Trying:</p>
  
  <pre><code>merge(df1,df2,by="Sales",all=TRUE)
  </code></pre>
  
  <p>does not work, because that makes rows that share the same values under "Sales" repeat themselves. Also, I don't want to see columns like "Date", "Price", and "SKU" repeat themselves in the merged data frame (I wind up with "Date.x", "Date.y", "Price.x", "Price.y", "SKU.x", "SKU.y").</p>
  
  <p>df1 </p>
  
  <pre><code>Date        Sales Price SKU
  2007/01/02   1     1.29 52648
  2007/01/02   2     1.99 48721
  2007/01/02   5     0.55 65897
  2007/01/02   6     5.00 56482
  2007/01/02   10    2.50 46521
  </code></pre>
  
  <p>df2</p>
  
  <pre><code>Date        Sales Price SKU   PVC
  2007/01/02   1     3.29 52647  Q
  2009/01/02   4     5.99 75677  Z    
  </code></pre>