title: calculate difference between values in different row and different column
body: <p>I have a dataframe like this:</p>
  
  <pre><code>ID  s1  e1  s2  e2
  A   50  150 80  180
  A   160 350 280 470
  A   355 700 800 1150
  B   100 500 150 550
  B   550 1500    800 1750
  </code></pre>
  
  <p>When the ID is identical I would like to calculate the difference between values in consecutive rows but different columns (for ID A: s1 in row2 minus e1 in row1; s1 in row3 minus e1 in row2; s2 in row2 minus e2 in row1; s2 in row3 minus e2 in row2) and add these values to a new column (diff1 and diff2).</p>
  
  <p>The dataframe would then look like this:</p>
  
  <pre><code>ID  s1  e1  s2  e2  diff1   diff2
  A   50  150 80  180     
  A   160 350 280 470 10  100
  A   355 700 800 1150    5   330
  B   100 500 150 550     
  B   550 1500    800 1750    50  250
  </code></pre>
  
  <p>Is this possible?</p>
  
  <p>Thank you in advance</p>
  
  <p>WD</p>