title: In R: How do I increment a column value based on multiples of a certain value in the adjacent column
body: <p>I'm quite new to R, unfortunately I wasn't able to find help in other related questions so far.</p>
  
  <p>I have this dataframe called selection, including column 'RUN' and column 'TRNO'.
  <img src="https://i.stack.imgur.com/pWEDz.png" alt="Selection dataframe"></p>
  
  <p>It originally had 9 columns. I added the column 'RUN' which contains a count that increases by 1 whenever the value in the column 'DAP' is 0, using this code: </p>
  
  <pre><code># Insert column RUN in "selection" dataframe
  
  library(dplyr)
  
  selection$RUN &lt;- cumsum(selection$DAP == 0)
  </code></pre>
  
  <p>That worked perfectly. Now I would like to do a similar operation for the column 'TRNO'. It also needs to contain a count that this time only increases when the column 'RUN' arrives at multiples of 80 (i.e. from RUN == 1-80 --> count =1; RUN == 81-160 --> count =2,...)</p>
  
  <p>I tried several codes, amongst others this one: </p>
  
  <pre><code># Insert column TRNO in "selection" dataframe
  
  i = 0
  
  repeat{
  
     i = i+80
  
     selection$TRNO &lt;- cumsum(selection$RUN == i)
  
     break
  
   }
  </code></pre>
  
  <p>Instead of increasing the count at every multiple of 80, it returns "0" when RUN values are between 1-80, increases to 92 when RUN values are at 80, and then stagnates at 92 for all the higher values in RUN.</p>
  
  <p><img src="https://i.stack.imgur.com/pWEDz.png" alt="Selection edataframe including column &#39;RUN&#39; and column &#39;TRNO"></p>