[R] Lag Function

Erik Iverson eriki at ccbr.umn.edu
Mon Mar 22 17:37:10 CET 2010


Hello,

Downey, Patrick wrote:
> Can anyone tell me what's going on here?
> 
> x <- matrix(data=c(1,2,3,4,5),ncol=1)
> x1 <- lag(x,k=1)
> x
> x1
> x - x1
> 
> That's with x specified as a column vector, but the same thing happens when
> it's a row vector.
> 
> x <- c(1,2,3,4,5)
> x1 <- lag(x,k=1)
> x
> x1
> x - x1
> 

I'm not sure what you're expecting to happen.  Can you clarify what 
needs explaining?  My guess is that the 'lag' function is not doing what 
you expect, but you don't say what you expect.


> When the documentation says "Vector or matrix arguments x are coerced to
> time series." What does that mean?

Time series are a class of objects in R, it means if you don't pass the 
lag function a time series object, it's going to try to turn it into one.



More information about the R-help mailing list