L: Lag of a Time Series

Description Usage Arguments Value Examples

View source: R/ts_lag_ops.R

Description

L shifts the values in an xts time series by the specified number of lags. The function extends the lag function by allowing users to specify a frequency with which to lag the variable.

Usage

1
L(x, lag = 1)

Arguments

x

'xts' time series variable

lag

numeric or character value indicating the number of periods to lag x. Defaults to one lag. Character inputs indicate the type of time period to lag. lag accepts 'y' years, 'q' quarters, 'm' months, 'w' weeks, and 'd' days. Number and character values can be combined.

Value

new 'xts' object shifted by the lag number of periods.

Examples

1
2
3
4
5
Y <- pwt(country = 'USA', series = 'gdp')
l_Y <- L(Y)       # GDP lagged by 1 period (quarter)
y_Y <- L(Y, 'y')  # GDP lagged by 1 year
m_Y <- L(Y, '6m') # GDP lagged by 6 months
#Table(Y, l_y, y_Y, m_Y)

cmann3/recon documentation built on May 13, 2019, 8:23 p.m.