There is a seq.POSIXt
function which has the nice property that the by
argument will get parsed for "numeric interval" meaning. If you print the results with format(z, "%H%M", tz="GMT")
it will appear as desired:
format( seq.POSIXt(as.POSIXct(Sys.Date()), as.POSIXct(Sys.Date()+1), by = "5 min"),
"%H%M", tz="GMT")
[1] "0000" "0005" "0010" "0015" "0020" "0025" "0030" "0035" "0040" "0045" "0050"
[12] "0055" "0100" "0105" "0110" "0115" "0120" "0125" "0130" "0135" "0140" "0145"
[23] "0150" "0155" "0200" "0205" "0210" "0215" "0220" "0225" "0230" "0235" "0240"
[34] "0245" "0250" "0255" "0300" "0305" "0310" "0315" "0320" "0325" "0330" "0335"
[45] "0340" "0345" snipped the rest.
Unless you are within 360/48 degrees of Greenwich (or is it Paris) you need to put in the tz="GMT"
so that the offset for your timezone does not appear. Without that this produced a sequence starting at "1700" for me. You could assign the inner result to a name if you needed to keep it arount but it would not be a character value but rahter a POSIXct object:
z <- seq.POSIXt(as.POSIXct(Sys.Date()), as.POSIXct(Sys.Date()+1), by = "5 min")
> z[1]
[1] "2014-09-09 17:00:00 PDT"