title: Counter variable with conditions
body: <p>I have a simple problem but somehow can't figure out the solution... </p>
  
  <p>Here is an example of a data set:</p>
  
  <pre><code>dt = data.table(A=rep(c(1:2), each = 5), B = c(1,1,2,2,3,1,2,3,3,1), C =c("a","b","b","b","b","b","a","b","a","a"))
  </code></pre>
  
  <p>Basically, I want a counter counter variable which repeats it's value only when conditions are met. The conditions are that the subsequent rows in A should be the same, in B they should differ and in C they should be the same. This is the desired output:</p>
  
  <pre><code>dt = data.table(A=rep(c(1:2), each = 5), B = c(1,1,2,2,3,1,2,3,3,1), C =c("a","b","b","b","b","b","a","b","a","a"), counter = c(1,2,2,3,3,4,5,6,7,7))
  </code></pre>
  
  <p>As you can see, counter variable repeats it's value only when these conditions are met.</p>
  
  <p>Thanks!</p>