title: Add a different value (by groups) to another value in dataframe in R
body: <p>I have two dataframes, I want to subtract the value of column in one dataframe to another, if dataframes are equal in value of another column.</p>
  
  <p>I have two dataframes A and B that are similar to the following:</p>
  
  <pre><code>[A]
  Col1   Col2
   1      cat
   2      dog
   3      bird
   4      cat
   5      dog
  
  [B]
   Col1    Col2
  [cat]   1
  [dog]   2
  [bird]  3
  </code></pre>
  
  <p>I want to be able to add the values <code>A$Col1 + B$Col2</code> if <code>A$Col2</code> matches the tag of <code>[B]</code> and create a list with the results that will have the same length as the rows in <code>[A]</code></p>
  
  <p>I have tried this code </p>
  
  <pre><code>(A$Col1-B$Col2)[A$Col2==B$Col1]
  </code></pre>
  
  <p>which seems to work, but a following warning shows up:</p>
  
  <blockquote>
    <p>longer object length is not a multiple of shorter object length</p>
  </blockquote>