title: Split column into segments by groups of start/stop intervals
body: <p>I have a very simple data frame where ID is a number sequence and there are multiple groups, where beginnings/endings are denominated with start/stop:</p>
  
  <pre><code>ID = c(1:20)
  group = c(NA,1,NA,NA,NA,1,NA,NA,NA,2,NA,NA,NA,NA,NA,2,NA,NA,NA,NA) %&gt;% as.factor()
  type = c(NA,"start",NA,NA,NA,"stop",NA,NA,NA,"start",NA,NA,NA,NA,NA,"stop",NA,NA,NA,NA) %&gt;% as.factor()
  
  df = data.frame(ID,group,type)
  head(df)
  
     ID group  type
  1   1  &lt;NA&gt;  &lt;NA&gt;
  2   2     1 start
  3   3  &lt;NA&gt;  &lt;NA&gt;
  4   4  &lt;NA&gt;  &lt;NA&gt;
  5   5  &lt;NA&gt;  &lt;NA&gt;
  6   6     1  stop
  </code></pre>
  
  <p>I would like to fill the NAs in group with the adjacent values and split the data frame into segments between the start/stop intervals:</p>
  
  <pre><code>   ID group  type
  1   2     1 start
  2   3     1  &lt;NA&gt;
  3   4     1  &lt;NA&gt;
  4   5     1  &lt;NA&gt;
  5   6     1  stop
  6  10     2 start
  7  11     2  &lt;NA&gt;
  8  12     2  &lt;NA&gt;
  9  13     2  &lt;NA&gt;
  10 14     2  &lt;NA&gt;
  11 15     2  &lt;NA&gt;
  12 16     2  stop
  </code></pre>
  
  <p>If the missing values in group could be replaced, then the data frame could simply be reduced to values in group that are not NAs. I have looked at <code>tidyr::fill()</code>, but cannot find a good solution. Any suggestions will be much appreciated!</p>