[R] lag function doesn't work - what am i doing wrong?
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Oct 10 19:44:07 CEST 2008
lag1resid is a time series, try
str(residsq)
str(lag1residsq)
The problem is that when you subscript lag1resid you
don't get a time series out from that. See ?window.ts
or try the zoo or xts packages where subscripting of time
series works.
On Fri, Oct 10, 2008 at 1:27 PM, Scotty Nelson <poorboy44 at hotmail.com> wrote:
>
> I am trying to lag a time series. My data is in a matrix, but I coerce it
> into a ts object.
> But when I lag it and then look at the result, nothing has changed. What am
> I doing wrong?????
>
> residsq<-resid^2
> residsq<-as.ts(residsq)
> lag1residsq<-lag(residsq,-1)
>
>> residsq[1:5]
> 1 2 3 4 5
> 87.759 329882.188 5325849.333 31512.334 70865.228
>> lag1residsq[1:5]
> 1 2 3 4 5
> 87.759 329882.188 5325849.333 31512.334 70865.228
>>
>
> PS: I tried to lag the series manually using rbind(0, residsq), but the
> result ended up returning me [ 0, residsq(1), 0, residsq(2), 0, ....]
> WTF!!!! how do you stack 1 element onto another in R?
> --
> View this message in context: http://www.nabble.com/lag-function-doesn%27t-work---what-am-i-doing-wrong--tp19922651p19922651.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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