lagk: Lag a vector

Description Usage Arguments Value Examples

Description

This function computes a lagged vector, shifting it back or forward.

Usage

1
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

1
2
3
4
5
6
7
8
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)

statip documentation built on Nov. 18, 2019, 1:06 a.m.