title: Conditional cumulative sum
body: <p>I have this data frame</p>
  
  <pre><code>t&lt;-data.frame(v1=c(1,2,1,4,6,7,8,2,3,4,8,1,2), v2=c(2,3,6,1,-3,-2,1,2,-3,6,7,-2,1))
  </code></pre>
  
  <p>Scanning the data.frame from top to bottom, I want to get the cumulative sum of v1 for as long as v2 is positive. When v2 becomes negative, it should stop, record the value (of the cum.sum up to then) and the cumulative sum should restart again from the next first positive v2 and so on. So that in the end for the above data frame would be be the vector</p>
  
  <pre><code>8, 10 , 12, 2
  </code></pre>
  
  <p>Any ideas?</p>