[R] Time Series
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jan 15 16:20:07 CET 2009
Try this:
library(chron)
times("9:00:00") + 0:479/(24*60)
Also see R News 4/1 and read the help pages in chron.
If you eventually want to use these times with corresponding series
data look at the zoo package.
On Thu, Jan 15, 2009 at 10:01 AM, Andrew Choens <andy.choens at gmail.com> wrote:
> If I want to make a numerical series, I can do so easily with:
>
> series.numbers <- 1:10
>
> But, I don't seem to be able to do the same with time. I want to create
> a vector with 480 points that corresponds to the 480 minutes in a 8 hour
> work day. Thus I want series.time to look something like this:
>
> 9:00
> 9:01
> 9:02
> 9:03
> etc.
>
> Last night I managed to build this by concatenating a series of strings,
> and converting them to datetime format with as.Date() or strptime(), but
> my method seems overly complex.
>
> hour <- 0:59
> day <- c(9, 10, 11, 12, 13, 14, 15, 16)
> hours <- c(rep(9, 60), rep(10, 60), rep(11, 60), rep(12, 60),
> rep(1, 60), rep(2, 60), rep(3, 60), rep(4, 60))
> one.day <- paste(hours, ":", hour, sep = "")
> strptime(one.day, "%H:%M")
> # OR
> # as.Date(one.day, "%H:%M")
>
>
>
> Is there any way to do something similar to:
> strptime("09:00", "%H:%M") : strptime("11:00", "%H:%M")
>
> When I try this, I get the following error:
> numerical expression has 9 elements: only the first used
>
> Thanks.
> --andy
>
> --
> Insert something humorous here. :-)
>
> ______________________________________________
> 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