I wish to convert 10-minute time blocks into 1-minute time blocks for a large vector. My datatime values are spaced at 10-minutes intervals, which represent a 10-minute time block ending at the given time stamp. Example data below:
data<- structure(list(datetime = structure(1:7, .Label = c("30/11/2011 02:32",
"30/11/2011 02:42", "30/11/2011 02:52", "30/11/2011 03:02", "30/11/2011 03:12",
"30/11/2011 03:22", "30/11/2011 03:32"), class = "factor"), count =
c(100L, 60L, 10L, 10L, 200L, 180L, 190L)), .Names = c("datetime", "count"), class =
"data.frame", row.names = c(NA, -7L))
I have successfully converted the 10-minute time blocks into 1-minute blocks, between the first and last datetime values in my vector, using the xts package as follows:
data$datetime <- strptime(data$datetime, format="%d/%m/%Y %H:%M")
data$datetime <- as.POSIXct(data$datetime)
data_xts <- as.xts(data, order.by=data$datetime)
dtmins <- seq(start(data_xts$datetime), end(data_xts$datetime), by = "1 min")
However, as the time values relate to the ‘end’ of a 10-minute block, I also require nine rows of 1-minute datetime values to be created, prior to the first datetime row in my vector. I wish to end up with an output vector that looks like the below (and continues on to the last datetime value in my original vector):
datetime
30/11/2011 02:23
30/11/2011 02:24
30/11/2011 02:25
30/11/2011 02:26
30/11/2011 02:27
30/11/2011 02:28
30/11/2011 02:29
30/11/2011 02:30
30/11/2011 02:31
30/11/2011 02:32
30/11/2011 02:33
30/11/2011 02:34
30/11/2011 02:35
30/11/2011 02:36
30/11/2011 02:37
etc...
I am struggling to find a solution. Any help would be much appreciated!