1

Is there a way to generate time-only sequences in R? I don't want to use dates; I need to generate all the times from 12:00:00 to 13:00:00 every 5 minutes.

seq() won't work here:

interval = min * 60
seq(from = times('12:00:00'), to = times('13:00:00'), by = interval)
Rubens
  • 14,478
  • 11
  • 63
  • 92
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
  • possible duplicate of [Creating a specific sequence of date/times in R](http://stackoverflow.com/questions/14009301/creating-a-specific-sequence-of-date-times-in-r) – Thomas Jul 11 '13 at 12:52
  • Another possible duplicate: [Generating sequence of dates](http://stackoverflow.com/questions/14706330/generating-sequence-of-dates?rq=1) – Thomas Jul 11 '13 at 12:53
  • @Thomas The question is about time-only series. No dates. – Robert Kubrick Jul 11 '13 at 12:59
  • The principle is exactly the same, though. – Thomas Jul 11 '13 at 13:07
  • @Thomas If you call generating time series sequences the 'same principle' there are dozens of other questions on this site. – Robert Kubrick Jul 11 '13 at 13:30

1 Answers1

4

Your code works almost verbatim with chron:

> library(chron)
> min <- 5
> interval <- min / (60 * 24)
> seq(from = times('12:00:00'), to = times('13:00:00'), by = interval)
 [1] 12:00:00 12:05:00 12:10:00 12:15:00 12:20:00 12:25:00 12:30:00 12:35:00
 [9] 12:40:00 12:45:00 12:50:00 12:55:00 13:00:00

Alternately interval could be specified like this:

interval <- times("00:05:00")
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341