[R] leap years in temporal series command ts
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Feb 16 16:21:49 CET 2011
On Wed, Feb 16, 2011 at 6:51 AM, Peter Zorglub <peter.zorglub at gmail.com> wrote:
> Hi R community!
>
> I'd like to create a temporal series with ts command for the interval 1st
> January 2002 - 31 December 2008. I have daily values, so this is a 2557 days
> temporal series. I'm using this command :
>
> ts(observations, start=2002, end=2009, freq=365)
>
> However, I don't get the correct temporal series since both frequency (365
> OR 366 for leap years) and deltat (1/365 OR 1/366) are varying with the year
> considered.
>
> So, is there a specific way to deal with leap years in the ts command or
> have I to use another package?
You could do this with an implied frequency of 1
tt <- ts(1:10, start=as.Date("2000-01-01"))
which would represent the times as days since the Epoch. You can
recover the Date class dates with:
as.Date(tt, origin = "1970-01-01")
You might be better off using zoo or xts. e.g.
library(zoo)
z <- zooreg(1:10, start = as.Date("2000-01-01"))
Its also possible to move back and forth:
as.ts(z)
as.zoo(tt)
aggregate(as.zoo(tt), identity, as.Date)
--
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