lag.uts: Lag Observation Values

Description Usage Arguments Details Value Note See Also Examples

View source: R/lag.R

Description

Compute a lagged version of a time series by shifting observation values.

Usage

1
2
## S3 method for class 'uts'
lag(x, k = 1, ...)

Arguments

x

a "uts" object.

k

the number of lags (in units of observations).

...

further arguments passed to or from methods.

Details

Each observation time-value tuple (t[n], x[n]) in the original time series is replaced by (t[n], x[n-k]) in the lagged time series. Observations without corresponding un-lagged value (for example, the second observation for lag k=3) are dropped from the output.

Value

A "uts" object with the same observation times (apart from dropped observations) as x.

Note

For an evenly spaced time series (1) shifting observation times, and (2) shifting observation values essentinally gives the same result. For unevenly spaced time series, however, these two operations are quite different. The former affects only the observation times, while the latter affects only the observation values (apart from observations that are dropped).

See Also

lag_t allows to shift observation times, as opposed to observation values.

lag in base R.

Examples

1
2
3
4
5
6
7
8
# Shift observations values forward by one observation
lag(ex_uts(), k=1)

# Shift observations values forward by two observations
lag(ex_uts(), k=-2)

# If the lag 'k' is >= the length of the time series, all observations are dropped
lag(ex_uts(), k=6)

andreas50/uts documentation built on April 8, 2021, 10:03 a.m.