stlag | R Documentation |
Calculate the lag/forward terms of variables and vectors
stlag(x, ...)
## Default S3 method:
stlag(x, time, n = 1L)
## S3 method for class 'data.frame'
stlag(df, varlist = NULL, time = NULL, by = NULL, n = 1L, mode = NULL)
x |
a vector. |
time |
a interger vector object for x, and a name or string for df. For x, time length must equal to x. |
n |
an integer. |
df |
a a data.table or data.frame object. If hoping update by reference, data.table is required. |
varlist |
Variable names needed to calculate lagged terms. a bare name and a character vector are acceptable. |
by |
Names of variables used to grouping data. |
mode |
|
stlag(default)
: Calculate lag term of vector
stlag(data.frame)
: Calculate lag terms of data.frame/data.table variables
time = rep(2001:2006)
x = sample(6)
stlag(x, time)
ts <- data.table(time = 2001:2009, x = 1:9, y = sample(letters, 9))
stlag(ts, x, time = "time", mode = "list")
stlag(ts, x, time)
stlag(ts, y, time, n = -1L)
xt <- data.frame(
id = rep(c("a", "b"), each = 5),
time = rep(2001:2005, 2),
x = 1:10,
y = sample(letters, 10, replace = TRUE),
z = sample(LETTERS, 10, replace = TRUE)
)
stxtset(xt, id, time)
stlag(xt, x, n = -1L, mode = "list")
stlag(setDT(xt), x)
xt
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.