[R] How to create sequence of constant time interval

Gabor Grothendieck ggrothendieck at gmail.com
Mon Feb 16 12:04:27 CET 2009


Try this (and see R News 4/1 for more).

> library(chron)
> tt <- times(0:47/48)
> tt
 [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

> chron(rep("1/1/09", length = length(tt)), tt)
 [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:
>
> 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.
>
>
>
>
>
>
> --
> View this message in context: http://www.nabble.com/How-to-create-sequence-of-constant-time-interval-tp22034441p22034441.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list