Re: [R] Time alignment of time series

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue 26 Apr 2005 - 11:41:46 EST

On 4/25/05, Fernando Saldanha <fsaldan1@gmail.com> wrote:
>
> One thing that has given me trouble is the fact that the time series
> implementation in the class ts relies on the concept of a "start" to
> the time series. For example, if I have
>
> ts1 <- ts(c(1,2,3))
>
> dts1 <- diff(ts1)
>
> then dts1 will be a vector c(1,1) but with the attribute start = 2.
>
> Similarly, when one takes lags the "start" is moved around and the
> underlying vector itself is left untouched.
>
> Now, data frames seem to be able to deal with this. That is, if I do
> regressions involving these time series objects the data is correctly
> aligned. However, for some functions, like for example pairs() the
> data is misaligned. For example, if I call pairs with a series and
> itself lagged once and twice as the three arguments I only get points
> in the diagonals. The start attribute is ignored.
>
> Is there a simple way to avoid this problem? That is, is there a way
> to keep the data aligned by having functions take the start attribute
> into account?

 Bind your series, x, together with its lags to produce xx and then work with xx:
  x <- ts(seq(10)^2) # test data
 xx <- cbind(x = x, lagx = lag(x), lag2x = lag(x,2))  Depending on what you are doing you may or may not need to remove the NAs that are generated from this:
  xx.na <- na.omit(xx)

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Apr 26 11:47:16 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:26 EST