[R] How to create sequence of constant time interval

Tony Breyal tony.breyal at googlemail.com
Mon Feb 16 12:22:00 CET 2009


Something like the following might give a few ideas:

> start.date <- '2009-01-01'
> start.time <- '00:00:00'
> interval <- 30
>
> increment.mins <- interval * 60
> x <- paste(start.date, start.time)
>
> for(i in 1:20) {
+   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:
> 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-interva...
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list