title: Count number of times a variable is repeated continuously in R
body: <p>Consider following MWE:</p>
  
  <pre><code>df &lt;- data.frame(Day=1:10, Value = c("Yes","No","Yes", "Yes", "Yes", 
                                       "No", "No", "Yes","Yes",  "No"))
  
   Day Value
     1   Yes
     2    No
     3   Yes
     4   Yes
     5   Yes
     6    No
     7    No
     8   Yes    
     9   Yes
    10    No
  </code></pre>
  
  <p>I want an extra column that counts the number of times 'Value' is is already continuously 'yes'. So when Value is 'No', the new variable should always be 0. If it is the first time 'Yes' appears after 'No', it is set to 1. If then the next observations is also yes, it should be 2. As soon as the chain of 'Yes' is intermittent, the new variable for the next 'yes' will be 1 again. So my data frame should look like this:</p>
  
  <pre><code>Day Value Count
   1   Yes  1
   2    No  0
   3   Yes  1  
   4   Yes  2
   5   Yes  3
   6    No  0
   7    No  0
   8   Yes  1
   9   Yes  2
  10    No  0 
  </code></pre>
  
  <p>Hope someone can help me out.</p>