[R] Chron object in time series plot

Gabor Grothendieck ggrothendieck at gmail.com
Wed Oct 20 18:11:45 CEST 2010


On Wed, Oct 20, 2010 at 11:08 AM, Manta <mantino84 at libero.it> wrote:
>
> Sorry R community, I am still stucked wit this. How can avoid the x-limit
> error?

If the problem is that you wish to create and plot an hourly series at
12 successive hours starting at 7am then here are three ways depending
on whether we wish to use chron's "times" class, its "chron" class or
"POSIXct" class.  (Do not use "POSIXlt" class for this.)   We use 1,
2, 3, ..., 12 for the data of our series for these examples.   "chron"
measures time in days and there are 24 hours in a day hence freq = 24
in the first two examples.   POSIXct measures time in seconds and
there are 3600 seconds in an hour so deltat = 3600 in the third
example.    You can find further discussion in an article in R News
4/1.    Also see ?zooreg

# using "times" class

library(zoo); library(chron)
z1 <- zooreg(1:12, times("07:00:00"), freq = 24)
plot(z1, type = "o")

# using "chron" class

library(zoo); library(chron)
z2 <- zooreg(1:12, chron("1/1/1970", "07:00:00"), freq = 24)
plot(z2, type = "o")

# using "POSIXct" class

library(zoo)
z3 <- zooreg(1:12, as.POSIXct("1970-01-01 07:00:00"), deltat = 3600)
plot(z3, type = "o")

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list