This will make a list in which each element of the list is an xts object that starts at 8:30 and ends at 13:30 the next day.
D <- split(mts, "days") mts.days <- lapply(seq_along(D) - 1, function(i) { if (i > 0) rbind(D[[i]]["T08:30/T23:59:59"], D[[i + 1]]["T00:00:00/T13:30:00"]) })
Edit: The above can be extended by adding names to the list:
names(mts.days) <- as.Date(sapply(D, function(x) as.Date(start(x))))
Then you can refer to the data from 8:30 to 2012-01-30 to 1:30 pm. on 2012-01-31 like this
mts.days[["2012-01-30"]]
Alternatively, if you are only going to pull out one “day”, you can do something like this (this follows the same basic logic)
PullDay <- function(Date="2012-01-30", t0="08:30", t1="13:30", mts=mts) { string1 <- paste(Date, " ", t0, "/", Date, " 23:59:59", sep="") string2 <- paste(as.Date(Date) + 1, " 00:00:00/", as.Date(Date) + 1, " ", t1, sep="") rbind(mts[string1], mts[string2]) }
Then PullDay("2012-01-30") will provide you with a subset of the data from 2012-01-30 08:30 / 2012-01-31 13:30.
Edit2: It simplifies
PullDay <- function(Date="2012-01-30", t0="08:30", t1="13:30", mts=mts) { mts[paste(Date, " ", t0, "/", as.Date(Date) + 1, " ", t1, sep="")] }
which makes me think that I still don't understand what you want ...