Detect consequitive minutes in POSIXct in R

Solution 1:

Here is a base R approach -

with(rle(as.integer(c(difftime(dt[-1],dt[-length(dt)],units = 'mins'),0)) == 1), 
    dt[!duplicated(rep(seq_along(values), lengths)) & 
        rep(lengths >= 2 & values, lengths)])

#[1] "2020-01-01 09:35:00 +08" "2020-01-01 09:50:00 +08"
  • difftime calculates difference between consecutive timestamps.
  • Using rle we calculate lengths whose difference between timestamp is 1 minute.
  • Return only the starting timestamp of groups where length is greater than 2.