title: assigning new values based on the location in the sequence
body: <p>Working in R.
  The data tracks changes in brain activity over time. Column "mark" contains information when a particular treatment begins and ends. For examples, the first condition (mark==1) begins in row 3 and ends in row 6. The second experimental condition (mark==2) starts in row 9 and ends in 12. Another batch of treatment one is repeated between rows 15 and 18.</p>
  
  <pre><code>ob.id &lt;- c(1:20)
  mark &lt;- c(0,0,1,0,0,1,0,0,2,0,0,2,0,0,1,0,0,1,0,0)
  condition&lt;-c(0,0,1,1,1,1,0,0,2,2,2,2,0,0,1, 1,1,1,0,0)
  start &lt;- data.frame(ob.id,mark)
  result&lt;-data.frame(ob.id,mark,condition)
  print (start)
  &gt; print (start)
     ob.id mark
  1      1    0
  2      2    0
  3      3    1
  4      4    0
  5      5    0
  6      6    1
  7      7    0
  8      8    0
  9      9    2
  10    10    0
  11    11    0
  12    12    2
  13    13    0
  14    14    0
  15    15    1
  16    16    0
  17    17    0
  18    18    1
  19    19    0
  20    20    0
  </code></pre>
  
  <p>I need to create a column that would have a dummy variable indicating the membership of an observation in corresponding experimental condition, like this:</p>
  
  <pre><code>&gt; print(result)
     ob.id mark condition
  1      1    0         0
  2      2    0         0
  3      3    1         1
  4      4    0         1
  5      5    0         1
  6      6    1         1
  7      7    0         0
  8      8    0         0
  9      9    2         2
  10    10    0         2
  11    11    0         2
  12    12    2         2
  13    13    0         0
  14    14    0         0
  15    15    1         1
  16    16    0         1
  17    17    0         1
  18    18    1         1
  19    19    0         0
  20    20    0         0
  </code></pre>
  
  <p>Thanks for your help!</p>