Reputation: 2949
I want to generate time sequence of a day by a minute difference using R like
00:00, 00:01, 00:02, ..., 23:59
For the same, I am using timeBasedSeq
function of xts package with following lines of code
timerange1<- paste('T00:00','/','T23:59',' 12:00',sep="")
timeBasedSeq(timerange1)
But, I am not able to generate the sequence with this. Also, I do not understand what 12:00
mean in first line of code, i.e., how does it relate to minutes or hours or seconds.
Any help will be appreciated.
Upvotes: 3
Views: 6341
Reputation: 887118
Or from the comments,
format(seq(as.POSIXct("2013-01-01 00:00:00", tz="GMT"),
length.out=1440, by='1 min'), '%H:%M')
Upvotes: 11
Reputation:
You don't respect the required format: CCYYMMDD HHMMSS
, in your case CCYYMMDD HHMM
. Try:
library(xts)
timerange1 <- "20160106 0000/20160106 2359"
seqMinute <- format(timeBasedSeq(timerange1), "%H:%M")
length(seqMinute)
# [1] 1440
range(seqMinute)
# [1] "00:00" "23:59"
Upvotes: 2