title: Taking one to many difference Between Groups in Tidy Data
body: <p>I have a tidy data set similar to the hear-rate example in <a href="https://blog.rstudio.org/2014/07/22/introducing-tidyr/" rel="nofollow noreferrer">Introducing tidyr blog post</a>, but I have an additional "placebo" group under the drug which I can construct like this</p>
  
  <pre><code>library(dplyr)
  library(tidyr)
  messy &lt;- data.frame(
    name = c("Wilbur", "Petunia", "Gregory"),
    a = c(67, 80, 64),
    b = c(56, 90, 50),
    p = c(60, 70, 60)    # this is the new 'placebo' drug
  )
  tidy &lt;- messy %&gt;% 
          gather(drug, heartrate, a:p)
  </code></pre>
  
  <p>Assuming I start with tidy data, my goal is to create a new variable called "diff.p" which is the difference between the observation for each drug and the placebo. The results should look like this </p>
  
  <pre><code>tidy$diff.p &lt;- c(7,10,4,-4,20,-10,0,0,0)
  tidy
  </code></pre>
  
  <p>It seems like <code>ave</code> and/or <code>mutate</code> might be good paths to the solution (or perhaps constructing a new data frame?), but I need some additional guidance on best practice. </p>