Skip to content

How to create sequence of constant time interval

6 messages · Suresh_FSFM, Tony, Gabor Grothendieck

#
Dear R-Experts, 

seek your help.

There are two parts I want to deal with.
1) 
I want to create a time interval of say, 30 minutes starting from "00:00:00"
hrs
Thus at the end, I want to create sequence:
00:00:00
00:30:00
01:00:00 
01:30:00
..
..
How to do so ?
Later, I want to change the time-increment value in a variable and changing
the value of this variable, I would like to create new sequence with that
time increment. How to use "seq()" correctly?

2)
I have a date stored in one variable. Say "2009-01-01"
How can I combine this date with each time interval in the first part? Will
concatenate work?
so at the end, I would like to have:

2009-01-01 00:00:00
2009-01-01 00:30:00
2009-01-01 01:00:00
2009-01-01 01:30:00
...
...

Thank you in advance.
#
Try this (and see R News 4/1 for more).
[1] 00:00:00 00:30:00 01:00:00 01:30:00 02:00:00 02:30:00 03:00:00
03:30:00 04:00:00 04:30:00 05:00:00 05:30:00 06:00:00 06:30:00
07:00:00 07:30:00
[17] 08:00:00 08:30:00 09:00:00 09:30:00 10:00:00 10:30:00 11:00:00
11:30:00 12:00:00 12:30:00 13:00:00 13:30:00 14:00:00 14:30:00
15:00:00 15:30:00
[33] 16:00:00 16:30:00 17:00:00 17:30:00 18:00:00 18:30:00 19:00:00
19:30:00 20:00:00 20:30:00 21:00:00 21:30:00 22:00:00 22:30:00
23:00:00 23:30:00
[1] (01/01/09 00:00:00) (01/01/09 00:30:00) (01/01/09 01:00:00)
(01/01/09 01:30:00) (01/01/09 02:00:00) (01/01/09 02:30:00) (01/01/09
03:00:00)
 [8] (01/01/09 03:30:00) (01/01/09 04:00:00) (01/01/09 04:30:00)
(01/01/09 05:00:00) (01/01/09 05:30:00) (01/01/09 06:00:00) (01/01/09
06:30:00)
[15] (01/01/09 07:00:00) (01/01/09 07:30:00) (01/01/09 08:00:00)
(01/01/09 08:30:00) (01/01/09 09:00:00) (01/01/09 09:30:00) (01/01/09
10:00:00)
[22] (01/01/09 10:30:00) (01/01/09 11:00:00) (01/01/09 11:30:00)
(01/01/09 12:00:00) (01/01/09 12:30:00) (01/01/09 13:00:00) (01/01/09
13:30:00)
[29] (01/01/09 14:00:00) (01/01/09 14:30:00) (01/01/09 15:00:00)
(01/01/09 15:30:00) (01/01/09 16:00:00) (01/01/09 16:30:00) (01/01/09
17:00:00)
[36] (01/01/09 17:30:00) (01/01/09 18:00:00) (01/01/09 18:30:00)
(01/01/09 19:00:00) (01/01/09 19:30:00) (01/01/09 20:00:00) (01/01/09
20:30:00)
[43] (01/01/09 21:00:00) (01/01/09 21:30:00) (01/01/09 22:00:00)
(01/01/09 22:30:00) (01/01/09 23:00:00) (01/01/09 23:30:00)
On Mon, Feb 16, 2009 at 5:00 AM, Suresh_FSFM <suresh.ghalsasi at gmail.com> wrote:
#
Thank you very much for the precise response.


Regards,
Suresh
Suresh_FSFM wrote:

  
    
#
Something like the following might give a few ideas:
+   print(strptime(x, "%Y-%m-%d %H:%M:%S")  + i*increment.mins)
+ }
[1] "2009-01-01 00:30:00 GMT"
[1] "2009-01-01 01:00:00 GMT"
[1] "2009-01-01 01:30:00 GMT"
[1] "2009-01-01 02:00:00 GMT"
[1] "2009-01-01 02:30:00 GMT"
[1] "2009-01-01 03:00:00 GMT"
[1] "2009-01-01 03:30:00 GMT"
[1] "2009-01-01 04:00:00 GMT"
[1] "2009-01-01 04:30:00 GMT"
[1] "2009-01-01 05:00:00 GMT"
[1] "2009-01-01 05:30:00 GMT"
[1] "2009-01-01 06:00:00 GMT"
[1] "2009-01-01 06:30:00 GMT"
[1] "2009-01-01 07:00:00 GMT"
[1] "2009-01-01 07:30:00 GMT"
[1] "2009-01-01 08:00:00 GMT"
[1] "2009-01-01 08:30:00 GMT"
[1] "2009-01-01 09:00:00 GMT"
[1] "2009-01-01 09:30:00 GMT"
[1] "2009-01-01 10:00:00 GMT"

        
On 16 Feb, 10:00, Suresh_FSFM <suresh.ghals... at gmail.com> wrote:
#
ahh, didn't see Gabor's solution, that works much better :-)
On 16 Feb, 10:00, Suresh_FSFM <suresh.ghals... at gmail.com> wrote:
2 days later
#
For version 2.3-30 of chron which just appeared on CRAN this can
be simplified to:

library(chron)
tt <- times(0:47/48)
tt
chron("1/1/09", tt) # no rep needed

On Mon, Feb 16, 2009 at 6:04 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: