[R] lagged variables
ruipbarradas at sapo.pt
Wed Jul 25 11:08:11 CEST 2012
You are doing nothing wrong. Follow this example.
x <- ts(1:5)
# Seems the same with different start and end
# But it's not
Are there other functions? I know of at least one. (In the end.)
These two, though not lags, might also be of interess to you.
y <- window(x, start=2, end=5)
?window.zoo # package zoo
# Package: TSA
# Title: Time Series Analysis
# Version: 0.98
# Date: 2010-7-31
# Author: Kung-Sik Chan
function (x, d = 1)
if (d != as.integer(d) || d < 0)
stop("d must be a non-negative integer")
if (d == 0)
else return(c(rep(NA, d), rev(rev(x)[-(1:d)])))
Hope this helps,
Em 25-07-2012 09:10, saraberta escreveu:
> hi guys,
> i have some trouble in creating lagged variables to use as external
> i'm trying to use lag(x) but it gives me as result the same time series (x),
> adding this part at the end:
>  0 2323 1
> where do i wrong?are there other functions to be used?
> View this message in context: http://r.789695.n4.nabble.com/lagged-variables-tp4637734.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> 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