title: Adding a column to a data set under a certain condition of weights
body: <p>I am giving a data set called ChickWeight. This has the weights of chicks over a time period. I need to introduce a new variable that measures the current weight difference compared to day 0. The data set is in library(datasets) so you should have it. </p>
  
  <pre><code>library(dplyr)
  
  weightgain &lt;- ChickWeight %&gt;% 
    group_by(Chick) %&gt;%
    filter(any(Time == 21)) %&gt;%
    mutate(weightgain = weight - first(weight))
  </code></pre>
  
  <p>I have this code, but this code just subtracts each weight by 42 which is the weight at time 0 for chick 1. I need each chick to be subtracted by its own weight at time 0 so that the weightgain column is correct.</p>