title: Select rows in dataframe conditional on a switching boolean variable in another column in R
body: <p>Let's say I have the following dataframe in R:</p>
  
  <pre><code>set.seed(23)
  
  # Create sample data
  time = 1:15
  x = rnorm(n = 15) 
  y = rnorm(n = 15)
  boolean = sample(c(TRUE,FALSE), 15, TRUE)
  df &lt;- data.frame(time, x, y, boolean)
  
  # Output
  &gt; df
  time           x            y boolean
  1     1  0.19321233  0.308136896    TRUE
  2     2 -0.43468211 -0.520178315    TRUE
  3     3  0.91326710 -0.442313801   FALSE # select
  4     4  1.79338809 -0.599312812    TRUE # select
  5     5  0.99660511  1.294577829    TRUE
  6     6  1.10749049  0.835391247    TRUE
  7     7 -0.27808628 -0.566015100    TRUE
  8     8  1.01920549  0.788419350   FALSE # select
  9     9  0.04543718 -1.165929326    TRUE # select
  10   10  1.57577959 -0.530820006   FALSE # select
  11   11  0.21828845 -0.001058737   FALSE
  12   12 -1.04653534 -0.512562365   FALSE
  13   13 -0.28868865  1.242867513   FALSE
  14   14  0.48155029 -0.660582851   FALSE
  15   15 -1.21637643  0.166624215    TRUE # select
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>I would like to select all the rows, in which the boolean in the 4th column switches from <code>FALSE</code> to <code>TRUE</code> or vice versa (indicated in the dataframe above). </p>
  
  <p><strong>Question</strong></p>
  
  <p>How do I do this in R?</p>
  
  <p><strong>Attempt</strong></p>
  
  <p>I have found the <code>select()</code> and the <code>select_if()</code> functions in the <code>tidyverse package</code>, however, I am not able to select the values based on the previous value in the column.</p>