title: How to get frequency counts using column breaks by row?
body: <p>I have a data frame which tracks service involvement (srvc_inv {1, 0}) for individual x (Bob) over a timeframe of interest (years 1900-1999). </p>
  
  <pre><code>library(tidyverse)
  
  dat &lt;- data.frame(name = rep("Bob", 100),
                day = seq(as.Date("1900/1/1"), as.Date("1999/1/1"), "years"),
                srvc_inv = c(rep(0, 25), rep(1, 25), rep(0, 25), rep(1, 25)))
  </code></pre>
  
  <p>As we can see, Bob has two service episodes: one episode between rows 26:50, and the other between rows 76:100. </p>
  
  <p>If we want to determine <em>any</em> service involvement for Bob during the timeframe, we can use a simple max statement as shown below. </p>
  
  <pre><code>dat %&gt;% 
    group_by(name) %&gt;% 
    summarise(ever_inv = max(srvc_inv))
  </code></pre>
  
  <p>However, I would like to determine the number of service episodes that Bob had during the timeframe of interest (in this case, 2). A distinct service episode would be identified by a break in service involvement over consecutive dates. Anybody have any idea how to program this? Thanks!</p>