title: Find Max & Min of one column and difference of two other columns in R
body: <p>I am working on a table named <strong>kpi</strong> where I need to calculate the difference of (B1 - B0) for each BoxID per week using the Minimum <strong>No.</strong> and Maximum <strong>No.</strong> for each BoxID per week -</p>
  
  <p>I couldn't calculate the <strong>First_b1, Last_b0 and Diff</strong>   </p>
  
  <pre><code>kpi &lt;- kpi %&gt;%
          mutate(weekNumber = week(dmy(Date))) %&gt;% 
          group_by(SolboxID, weekNumber) %&gt;%
          arrange(SolboxID)
  
  **Date      No.   BoxID B0      B1      WkNo**
  29.10.2018  61931   1   0       0       44
  15.11.2018  115763  1   5.38    5.38    46
  16.11.2018  119833  1   51.86   52.23   46
  29.10.2018  60486   3   23.26   22.97   44
  10.11.2018  99576   3   1336.53 1336.53 45
  14.11.2018  112259  3   1.19    1.04    46
  16.11.2018  117965  3   8.68    47.22   46
  16.11.2018  118092  3   47.22   47.22   46
  15.11.2018  115396  4   82.05   82.05   46
  </code></pre>
  
  <p>Expected output table -</p>
  
  <pre><code>Date        No.   BoxID B0      B1      WkNo   First_b1     Last_b0  Diff
  29.10.2018  61931   1   0       0       44     0            0        0
  15.11.2018  115763  1   5.38    5.38    46     52.23        5.38     46.85
  16.11.2018  119833  1   51.86   52.23   46     52.23        5.38     46.85
  29.10.2018  60486   3   23.26   22.97   44     22.97        23.26    -0.29
  10.11.2018  99576   3   1336.53 1336.53 45     1336.53      1336.53  0
  14.11.2018  112259  3   1.19    1.04    46     47.22        1.19     46.03
  16.11.2018  117965  3   8.68    47.22   46     47.22        1.19     46.03
  16.11.2018  118092  3   47.22   47.22   46     47.22        1.19     46.03
  15.11.2018  115396  4   82.05   82.05   46     82.05       82.05     0
  </code></pre>
  
  <p>I need some help to compute the 3 more columns. 
  Thank you in advance.</p>