title: is there an R function to filter a dataset in 15 secs interval?
body: <p>I am trying to filter a dataset of depth data and a corresponding date. 
  The Time column is a POSIXct <code>format = "%Y%m%d%H%M%S"</code>.
  This is how my data looks like:</p>
  
  <pre><code>Depth Time        
  0.1   2018-06-24 01:26:40  
  0.2   2018-06-24 01:26:41  
  0.2   2018-06-24 01:26:56  
  0.1   2018-06-24 01:26:57  
  0.1   2018-06-24 01:26:58  
  0.1   2018-06-24 01:26:59  
  0.1   2018-06-24 01:27:14  
  0.1   2018-06-24 01:27:15  
  0.1   2018-06-24 01:27:16  
  0.1   2018-06-24 01:27:17  
  0.1   2018-06-24 01:27:30  
  </code></pre>
  
  <p>I would like to create a dataframe containing the same data but only with a new entry every 15 seconds. My data is sometimes continuous and sometimes there is a gap in the recorded time.   </p>
  
  <p>This would be my desired output:  </p>
  
  <p>Depth Time<br>
  0.2   2018-06-24 01:26:41<br>
  0.2   2018-06-24 01:26:56<br>
  0.1   2018-06-24 01:27:14<br>
  0.1   2018-06-24 01:27:30  </p>
  
  <p>I tried using the time difference between rows which works for the parts of the dataset that is consecutive: </p>
  
  <pre class="lang-r prettyprint-override"><code>    dt_filter &lt;- d_cor %&gt;%  
      mutate(diff = Time - lag(Time, default = first(Time)))  
  
       if ((dt_filter$diff &lt; 2) ) {  
        dt_filter_1 &lt;- dt_filter[seq(1, nrow(dt_filter), 15), ]  
       }
  </code></pre>
  
  <p>but that gives me a problem once I try to add the ones in that are not consecutive:  </p>
  
  <pre><code>    dt_filter_15 &lt;- dt_filter %&gt;%    
        filter(diff &gt;= 15 )
  </code></pre>
  
  <p>Since then I don't always have an interval of 15 secs and it obviously doesn't count them in.  </p>
  
  <p>So far I could not find a function that is able to filter my Time column. I am quite new to R so not too familiar with writing my own loops which I guess is neccessary...and time data does not make it easier.</p>
  
  <p>Thanks for any help!</p>
  
  <p>EDIT </p>
  
  <p>@Ben Thanks for the quick replies!</p>
  
  <p>That is some of the output that I've got:</p>
  
  <pre><code>        Depth Time                diff cumdiff x
          0.1   2018-06-23 23:59:44 1    1030    0
          0.0   2018-06-24 00:01:02 78   1035    5
          0.0   2018-06-24 00:01:03 1    1036    1
  </code></pre>
  
  <p>between the last two lines is only 1s of difference, but it is still added to cumdiff and therefore counted in the x column</p>