title: Equal time between rows with R
body: <p>I have the following sample:</p>
  
  <pre><code>&gt; dput(data)
  structure(list(mmsi = c(992761085L, 992761085L, 992761085L, 992761085L, 
  992761085L, 992761085L, 992761085L, 992761085L, 992761085L, 992761085L, 
  992761085L, 992761085L, 992761085L, 992761085L, 992761085L, 992761085L, 
  992761085L, 992761085L, 992761085L, 992761085L), timestamp_pretty = structure(c(1L, 
  2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 
  16L, 17L, 18L, 19L, 19L), .Label = c("15/01/2015 00:02:06", "15/01/2015 00:05:09", 
  "15/01/2015 00:08:02", "15/01/2015 00:11:04", "15/01/2015 00:14:02", 
  "15/01/2015 00:17:06", "15/01/2015 00:20:07", "15/01/2015 00:23:05", 
  "15/01/2015 00:26:04", "15/01/2015 00:32:09", "15/01/2015 00:35:02", 
  "15/01/2015 00:38:05", "15/01/2015 00:41:06", "15/01/2015 00:44:02", 
  "15/01/2015 00:47:03", "15/01/2015 00:50:03", "15/01/2015 00:53:18", 
  "15/01/2015 00:56:07", "15/01/2015 00:59:07"), class = "factor")), .Names = c("mmsi", 
  "timestamp_pretty"), class = "data.frame", row.names = c(NA, 
  -20L))
  </code></pre>
  
  <p>I would like to remove some of the signals and to keep only signals every 6 minutes. </p>
  
  <p>I have the following function that will should select the signals every 6 minutes</p>
  
  <pre><code>library(chron)
  library(zoo)
  to180ch &lt;- function(x) trunc(as.chron(as.character(x), "%d/%m/%Y %H:%M:%S"), "00:06:00")
  for ( i in levels(data$mmsi) ){
    read.zoo(data, FUN = to180ch, aggregate = function(x) tail(x, 1))}
  
  test &lt;- subset(data, !duplicated(to180ch(timestamp_pretty), fromLast = TRUE))
  test &lt;- test[order(test$mmsi, test$timestamp_pretty),] 
  </code></pre>
  
  <p>but when I check the time difference in minutes between the signals, I sometimes have less than 6 minutes:</p>
  
  <pre><code>test&lt;-data.table(test)
  test[, timestamp_pretty:=as.POSIXct( timestamp_pretty, format="%d/%m/%Y %H:%M:%S", tz="UTC" )]
  test[,diff_time_seconds_timestamp_pretty:=c(NA,diff(timestamp_pretty)),by="mmsi"]
  </code></pre>
  
  <p>I got as final result:</p>
  
  <pre><code>dput(test)
  structure(list(mmsi = c(992761085L, 992761085L, 992761085L, 992761085L, 
  992761085L, 992761085L, 992761085L, 992761085L, 992761085L, 992761085L, 
  992761085L, 992761085L), timestamp_pretty = structure(c(1421280309, 
  1421280664, 1421281026, 1421281385, 1421281564, 1421282102, 1421282466, 
  1421282823, 1421283198, 1421283547, 1421283910, 1421284278), class = c("POSIXct", 
  "POSIXt"), tzone = "UTC"), diff_time_seconds_timestamp_pretty = c(NA, 
  5.91666666666667, 6.03333333333333, 5.98333333333333, 2.98333333333333, 
  8.96666666666667, 6.06666666666667, 5.95, 6.25, 5.81666666666667, 
  6.05, 6.13333333333333)), .Names = c("mmsi", "timestamp_pretty", 
  "diff_time_seconds_timestamp_pretty"), row.names = c(NA, -12L
  ), class = c("data.table", "data.frame"), .internal.selfref = &lt;pointer: 0x00000000001f0788&gt;)
  </code></pre>
  
  <p>In the column <code>diff_time_seconds_timestamp_pretty</code> (difference in minutes between the signals), I have for example 5,91 minutes; 5,8 minutes or even 2.9 minutes! I guess there is a problem with the filtering of the "at least 6 minutes".</p>
  
  <p>How can I have at least 6 minutes between the signals?</p>
  
  <p>Thank you</p>