title: Find difference between maximum value of group and current row with R
body: <p>Similar to this question <a href="https://stackoverflow.com/questions/24558328/how-to-select-the-row-with-the-maximum-value-in-each-group">here</a>, I am trying to find the difference between the maximum value of a group and the value of the current row. </p>
  
  <p>For instance, if I have the following dataset:</p>
  
  <pre><code>ID &lt;- c(1,1,1,2,2,2,2,3,3)
  Value &lt;- c(2,3,5,2,5,8,17,3,5)
  group &lt;- data.frame(Subject=ID, pt=Value)
  </code></pre>
  
  <p>How would I go about creating a new column called "diff" that would be the difference between the value of the current row and the maximum value in that group? </p>
  
  <p>Thank you for your help!</p>