What is happening is that by indexing the time series, you are losing the time series attributes. Here is a quick test that I ran. > x Time Series: Start = 1 End = 20 Frequency = 1 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > y <- lag(x,1) > y Time Series: Start = 0 End = 19 Frequency = 1 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 > x==y Time Series: Start = 1 End = 19 Frequency = 1 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [17] FALSE FALSE FALSE > str(x) Time-Series [1:20] from 1 to 20: 1 2 3 4 5 6 7 8 9 10 ... > str(x[1:10]) int [1:10] 1 2 3 4 5 6 7 8 9 10 > x[1:10] == y[1:10] [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE >
Notice that 'x==y' comes up false, but x[1:10]==y[1:10] is true. Also notice the 'str(x[1:10])' as compared to 'str(x)' On 3/17/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hi - I'm quite wondering what makes the lag operator does not work for my > time series. I have a time series of length about 200000 elements. I would > like to have a lag 1 of this time series. I did the following: > > logprice = log(price, base=exp(1)) > # this is my log price which is a vector of price time series of length > 200000 > ts_logprice = as.ts(logprice, frequency=1) # convert to time series > lag_logprice = lag(ts_logprice, 1) # get the lag > > When I do: > > ts_logprice[1:10] == lag_logprice[1:10] > > The result returns TRUE for the first 10 elements which I do not expect > that. > > Is there any reason to this? I'd appreciate if you could let me know. > Thank you so much. > > - adschai > > [[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 > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[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 and provide commented, minimal, self-contained, reproducible code.