diff.uts: Lagged Differences

Description Usage Arguments Note See Also Examples

View source: R/diff.R

Description

Return a time series with suitably lagged differences of the observation values. Observation times without corresponding lagged observation time (for example, the second observation for lag=3) are dropped from the output.

Usage

1
2
## S3 method for class 'uts'
diff(x, lag = 1, scale = "abs", ...)

Arguments

x

a "uts" object.

lag

an integer indicating which lag to use.

scale

on which scale to calculate differences. Either "abs" for absolute differences x[n] - x[n - lag], "rel" for relative differences x[n] / x[n - lag] - 1, or "log" for logarithmic differences log(x[n] / x[n - lag]).

...

further arguments passed to or from methods.

Note

For an evenly spaced time series, calculating differences over (1) a certain number of observations (e.g. over four observations for quarterly data), and (2) over a fixed time horizon (e.g. over one year) gives the same result. For unevenly spaced time series, however, these two operations are quite different.

See Also

diff_t allows to calculate differences over a fixed time horizon, as opposed to number of observations.

diff in base R.

Examples

1
2
3
4
diff(ex_uts())
diff(ex_uts(), lag=-3)
diff(ex_uts(), scale="log")
diff(ex_uts(), lag=10)     # an empty time series, because the lag is too large

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