diff_t: Rolling Differences

Description Usage Arguments Details Methods (by class) Note See Also Examples

View source: R/diff.R

Description

Return a time series with differences over a fixed time horizon.

Usage

1
2
3
4
diff_t(x, ...)

## S3 method for class 'uts'
diff_t(x, by = NULL, scale = "abs", ...)

Arguments

x

a time series object.

...

further arguments passed to or from methods.

by

a finite duration object, specifying over which time horizon to calculate differences in observation values.

scale

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

Details

The time series difference at observation time t for time horizon by is calculated between the values x_t and x[t - by] on a suitable scale. Here, x[t - by] is the sampled value of x at time t - by, see sample_values.

Observations times for which no difference can be calculated (i.e. times t_i with t_i - by < t_1) are dropped from the output.

Methods (by class)

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 allows to calculate differences over a fixed number of observations, as opposed to time horizon.

Examples

1
2
diff_t(ex_uts(), by=ddays(1))
diff_t(ex_uts(), by=ddays(5)) # an empty time series, because the time difference is too large

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