title: Create a sequence conditional on values in other columns in R
body: <p>I am working with a dataframe similar to the following:</p>
  
  <pre><code> df = data.frame(ID1 = c(2,2,2,2,2,2,2), 
              ID2 = c(1,1,1,1,1,1,1),
              flagTag = c(0,0,0,0,1,0,0))
  </code></pre>
  
  <p>I need to create a new field "newField" such that the value increments when flagTag = 1 within group of ID1 and ID2 (thus unique records are identify by the combination of ID1 and ID2).The resulting table should look similar</p>
  
  <pre><code>    ID1 ID2 flagTag newField
    1   2   1       0     1
    2   2   1       0     1
    3   2   1       0     1
    4   2   1       0     1
    5   2   1       1     2
    6   2   1       0     2
  </code></pre>
  
  <p>I am trying to do this using dplyr but couldn't come up with a logic to do such manipulation. One way is to go record by record in the dataframe and update "newField" in loop which will be a slow procedure.</p>