Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

lagk

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)

statip

Statistical Functions for Probability Distributions and Regression

v0.2.3
GPL-3
Authors
Paul Poncet [aut, cre], The R Core Team [aut, cph] (C function 'BinDist' copied from package 'stats'), The R Foundation [cph] (C function 'BinDist' copied from package 'stats'), Adrian Baddeley [ctb] (C function 'BinDist' copied from package 'stats')
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.