title: R assign ID to records NOT using loops
body: <p>I need to loop through a data table "A" and depending on a condition assign an incremental ID to that record or group of records like:</p>
  
  <pre><code>library(data.table)
  A &lt;- data.table(x = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14), 
    y = c(2,2,2,2,2,2,2,2,3,3,3,3,3,3), z = 0)
  
  for(i in 1:nrow(A))
   {
     if((A[i]$x %% A[i]$y) == 0) {A[i]$z &lt;- i}
     print(i)
   }
  </code></pre>
  
  <p>the z column becomes a sort of a rolling ID.
  I need to perform the same operation without using loops. </p>