title: How to subtract every previous rows from the lead row to every five rows in R?
body: <p>I have a larger data frame that has multiple columns and thousands of rows. I want to replace the value of every lead row by subtracting the previous row value from the lead row for every five rows of the data frame. For example, the first value should retain its value, the second row should be: <code>second row - first row</code>. Similarly, the sixth row should retain its value, however, the seventh row would be <code>seventh row - sixth row</code>. Here is an example data frame</p>
  
  <pre><code>DF = data.frame(A= c(1:11), B = c(11:21))
  </code></pre>
  
  <p>The outputput should be like below</p>
  
  <pre><code>&gt; Output
      A  B
  1   1 11
  2   1  1
  3   1  1
  4   1  1
  5   1  1
  6   6 16
  7   1  1
  8   1  1
  9   1  1
  10  1  1
  11 11 21
  </code></pre>