[R] date and time

R. Michael Weylandt michael.weylandt at gmail.com
Fri Oct 14 20:46:40 CEST 2011


Good afternoon Robert,

Suppose you have your date and time in characters like this:

d.start = "2008-04-11"
t.start = "22:00:00"

d.end = "2008-04-12"
t.end = "15:00:00"

then use POSIXct to convert them to a unified time object:

start <- as.POSIXct(paste(d.start, t.start))
end <- as.POSIXct(paste(d.end, t.end))

Then simply use seq() on your objects, here:

OUT <- seq(start, end, by = 5) # 5 second steps.

Hope this helps,

(Robert) Michael Weylandt

On Fri, Oct 14, 2011 at 12:02 PM, threshold <r.kozarski at gmail.com> wrote:
> Dear R users,
>
> I got date and time as two separate characters
> [1] "2008-04-11"
> [1] "22:00:00"
>
> which correspond to my starting point in time domain.
>
> Now I need to produce series over, 5 sec epochs up to end point, say:
> [1] "2008-04-12"
> [1] "23:00:00"
>
> So something like
> 2008-04-11 22:00:00
> 2008-04-11 22:00:05
> 2008-04-11 22:00:10
> .
> .
> .
> 2008-04-12 23:00:00
>
> Is there any strightforward way to do it? Any suggestions?
>
> Best, robert
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/date-and-time-tp3905358p3905358.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