tlag: Creates a lagged variable of a vector.

Description Usage Arguments Value Examples

Description

Creates a lagged variable of a numerical vector without requiring it to be of time series class.

Usage

1
tlag(x, d = 1, na.rm = FALSE)

Arguments

x

A numeric, character or logical vector that needs to be lagged.

d

The number of lags (in units of observations). By default set to 1.

na.rm

A logical that indicates whether NA elements should be removed from the output or not. By default set to FALSE.

Value

A numeric vector of the same length as x if na.rm is set to FALSE, otherwise it is of the same length as x without NA elements.

Examples

1
2
3
4
5
6
# create some numeric vector
x <- 1:10

# lag t-1, without removing the resulting NA elements and with removal
tlag(x, 1, FALSE)
tlag(x, 1, TRUE)

hstojic/hfunk documentation built on May 17, 2019, 6:16 p.m.