lagk {statip} | R Documentation |
Lag a vector
Description
This function computes a lagged vector, shifting it back or forward.
Usage
lagk(x, k, na = FALSE, cst = FALSE)
Arguments
x |
A vector.
|
k |
integer. The number of lags.
If k < 0 , la serie est avancee au lieu d'etre retardee.
|
na |
logical. If na = TRUE and k > 0
(resp. k < 0 ), the |k| holes created in the lagged vector
are put to NA ; otherwise, the imputation depends on cst .
|
cst |
logical.
If na = FALSE and cst = TRUE , the |k| holes
created in the lagged vector are put to x[[1L]]
(or to x[[length(x)]] if k < 0 ).
If na = FALSE and cst = FALSE ,
these |k| holes are imputed by the k
first values of x (or the k last values if k < 0 ).
|
Value
A vector of the same type and length as x
.
Examples
v <- sample(1:10)
print(v)
lagk(v, 1)
lagk(v, 1, na = TRUE)
lagk(v, -2)
lagk(v, -3, na = TRUE)
lagk(v, -3, na = FALSE, cst = TRUE)
lagk(v, -3, na = FALSE)
[Package
statip version 0.2.3
Index]