title: How do you combine two data frames with quantities of items in R?
body: <p>I am working in <code>R</code> using data frame containing quantities of items (which are non-negative integers).  Here is an example of two data frames called <code>BASKET1</code> and <code>BASKET2</code>.  In both cases, an item appears in the data frame only if it has a quantity of at least one.  Items appear in each data frame in alphabetical order.</p>
  
  <pre><code>BASKET1
      Vegetable  Quantity
  1     Carrots         3
  2   Cucumbers         2
  3    Parsnips         5
  4      Celery         1
  5      Onions        12
  
  BASKET2
      Vegetable  Quantity
  1     Carrots        10
  2      Onions         6
  3     Rhubarb         2
  </code></pre>
  
  <p>I am trying to create a function that combines two baskets of items into a single basket, adding up all of the items in both baskets.  This is a kind of merge operation, except that I actually want to sum the quantities in the baskets.  It is quite simple to obtain the list of items by using the <code>unique</code> function:</p>
  
  <pre><code>VEGETABLES &lt;- unique(BASKET1$Vegetable, BASKET2$Vegetable);
  </code></pre>
  
  <p>I am having more difficulty finding a simple way to get the vector of quantities corresponding to this vector of items, to build the data frame of the combined baskets.  I think there is a way to do this using some kind of simple lookup query, but all the methods I have tried lead to code that is cumbersome.</p>
  
  <hr>
  
  <p><strong>Question:</strong> What is the simplest way to find the vector of quantities corresponding to the combined vector of items?</p>