title: Calculate difference scrore across factors in R
body: <p>I have the following dataframe  </p>
  
  <pre><code>    Class  Behavior   mean  
  1     BH Baseline     5   
  2     BH     Drnk     3   
  3     BH      Lvr     2
  4     BH     Tone     1
  5     NB Baseline     6
  6     NB     Drnk     3
  7     NB      Lvr     2
  </code></pre>
  
  <p>I want to generate a new column where I have calculated the difference from baseline for each class and behavior so for example:</p>
  
  <pre><code>    Class  Behavior   mean  diff  
  1     BH Baseline     5      0
  2     BH     Drnk     3      2
  3     BH      Lvr     2      3 
  4     BH     Tone     1      4
  5     NB Baseline     6      0
  6     NB     Drnk     3      3
  7     NB      Lvr     2      4
  </code></pre>
  
  <p>For each level of class, I want look at the difference between Baseline and all other Behaviors. I tried somethings using dplyr but I am just not sure how to make calculations across factor Baseline. Your help is appreciated. </p>