I have data of the following form:
DateTime | Var1
11/01/2016 06:01 | 0
11/01/2016 06:02 | 0.70
...
...
11/01/2016 23:59 | 35.08
11/02/2016 00:01 | 33.29
...
11/02/2016 06:00 | 24.62
...
11/30/2016 23:59 | 42.08
12/01/2016 00:01 | 39.79
....
I have ~5 months data. I have to subset the data from 6:00am of 1 day to just before 6:00am of next day. I can use the following code to subset the data once I have the dates in hand, but how to automatically obtain all the successive dates from the input data?
Date1 <- as.integer(as.POSIXct(Date1))
Date2 <- as.integer(as.POSIXct(Date2))
subset <- subset(data, as.integer(as.POSIXct(data$txtime)) >= Date1 & as.integer(as.POSIXct(data$txtime)) < Date2)
Right now, I can use to following code to obtain successive dates within a month, but this won't work for the last day of the month, where part of the data to be subsetted is on the first day of the next month. So I can't do it automatically for the duration 6:00am 30th November - 5:59am 1st December. Also, the code is not fully automated, as the number of days (used in the loop) varies across months.
for (dateofmonth in c(1:29)) {
Date1 <- paste("2016-11-", dateofmonth, ' 06:00:00', sep = '')
Date2 <- paste("2016-11-", (dateofmonth+1), ' 06:00:00', sep = '')
}
There is possibly an easier way to do this, but I can't figure it out. Please suggest.