0

Coincidentally, I found that my first column, a vector structured as POSIXct, has time gaps in it. My data set comprises observed values for each minute, however, for instance between 10:04:00 until 10:07:00 2 values are missing:

Date_time  
2016-05-11 10:02:00  
2016-05-11 10:03:00  
2016-05-11 10:04:00  
2016-05-11 10:07:00  
2016-05-11 10:08:00

I am working with a large data set and I would like to find out how many of those time gaps exists and at which position I can find them. I tried to work with the seq() command but I do not know how to use it for values of the class POSIXct. Thanks

4

1 回答 1

1

一些data.table解决方案:

library(data.table)
library(dplyr)
dt <- read.csv(text ='Date_time  
2016-05-11 10:02:00
2016-05-11 10:03:00
2016-05-11 10:04:00
2016-05-11 10:07:00
2016-05-11 10:08:00', as.is = T) %>% setDT()
dt[, Date_time := strptime(Date_time, "%Y-%m-%d %H:%M:%S")]
dt[, diff := Date_time - shift(Date_time)][, .N, by = diff]
##       diff N
## 1: NA mins 1
## 2:  1 mins 3
## 3:  3 mins 1
于 2017-05-23T12:46:48.423 回答