title: Sum based on two flags
body: <p>I need your help. I have a data with one numeric field and two flags. 
  I want to sum the numeric filed based on two flags .
  In the below data :
  I want to calculate sum between FLAG1 and FLAG2.  But when the FLAG2 is TRUE then the next FLAG1 row value should be made TRUE and before any FLAG2 is true , FLAG one should be considered as False.</p>
  
  <pre><code>nf&lt;-c(10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,180,190,200,210,220,230,240,250)
  Flag1 &lt;- c('FALSE','FALSE','FALSE','FALSE','FALSE','TRUE','FALSE','FALSE','FALSE','FALSE','FALSE','TRUE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','TRUE','FALSE','FALSE','FALSE','FALSE','FALSE')
  Flag2 &lt;- c('FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','TRUE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','TRUE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','FALSE','TRUE')
  
  
  abc &lt;- as.data.frame(cbind(Flag1,Flag2,nf))
  </code></pre>
  
  <p>Output I am looking for is  :
  numeric field sum of 300,910 and 1890.</p>
  
  <p>60+70+80+90 =300 100+110+120+130+140+150+160 After the second flag value is TRUE, firstflag next row value should become true and any subsequent value which is true in flag 1 should turn to false. </p>
  
  <p>please guide. </p>
  
  <p>Regards, Rohit</p>