[R] Help with lagSeries (Rmetrics, fCalendar)

Fernando Saldanha fsaldan1 at gmail.com
Mon May 22 23:36:11 CEST 2006


The function lagSeries calls the function timeSeries, which in turn
calls timeDate. (All three functions are in the package fCalendar)
During the call to timeDate the "positions" vector is altered. From
that point on one has problems doing arithmetic with the series. For
example,

ip.sa at positions
 [1] "1954-02-01 01:00:00" "1954-03-01 01:00:00" "1954-04-01 01:00:00"
 [4] "1954-05-01 01:00:00" "1954-06-01 01:00:00" "1954-07-01 01:00:00"
 [7] "1954-08-01 01:00:00" "1954-09-01 01:00:00" "1954-10-01 01:00:00"
[10] "1954-11-01 01:00:00"
> ip.sa.lag <- lagSeries(ip.sa)
> ip.sa.lag at positions
 [1] "1954-02-01 02:00:00" "1954-03-01 02:00:00" "1954-04-01 02:00:00"
 [4] "1954-05-01 02:00:00" "1954-06-01 02:00:00" "1954-07-01 02:00:00"
 [7] "1954-08-01 02:00:00" "1954-09-01 02:00:00" "1954-10-01 02:00:00"
[10] "1954-11-01 02:00:00"
> ip.sa + ip.sa.lag
Error in Ops.timeSeries(ip.sa, ip.sa.lag) :
        positions slot must match

My best guess for why this is happening is that timeDate thinks that
it is getting a date from the GMT time zone and converts it to the
Zurich time zone.

I am working with monthly data and I would rather avoid altogether
dealing with hours and minutes. Can this be done? I tried to build my
series with format = "%Y-%m-%d" but that did not help:

z <- timeSeries(matrix(c(1,2,3)), charvec = c("1954-02-01",
"1954-03-01", "1954-04-01"), format = "%Y-%m-%d")
> z
                    TS.1
1954-02-01 01:00:00    1
1954-03-01 01:00:00    2
1954-04-01 01:00:00    3

If I really have to put up with hours, minutes, and seconds, is there
a way to avoid having lagSeries change the hours as it did in the
first example above? I believe the arguments for lagSeries do not
include anything that would change the behavior of timeDate. So, I
guess, if there is a solution, it might be changing an environment
value. I set

Sys.putenv("TZ" = "GMT")

as recommended, and of course that did not help.

Thanks for any advice.

FS



More information about the R-help mailing list