[R] Odd results with lag

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 8 01:43:40 CEST 2011


On Thu, Apr 7, 2011 at 6:11 PM, Worik R <worikr at gmail.com> wrote:
> Given a vector:
>
>> S <- c(1,1,0,0,1,1,-1,-1,-1,0,1)
>
> Then I expected lag(S) to give...
>
> c(1,0,0,1,1,-1,-1,-1,0,1)
>
> but instead...
>
>> S
>  [1]  1  1  0  0  1  1 -1 -1 -1  0  1
>> lag(S)
>  [1]  1  1  0  0  1  1 -1 -1 -1  0  1
> attr(,"tsp")
> [1]  0 10  1
>>
>
> This is very odd.  What is happening?
>
> I get what I using S[-1] so I have no problem, but I obviously do not
> understand some thing!
>

lag lags the indexes not the data.   Try lag(ts(S))

-- 
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