I have the following dataframe
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
I want to generate a new column where I have calculated the difference from baseline for each class and behavior so for example:
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
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.