Learn R Programming

tsforecast (version 1.3.0)

tsdiff: Difference a Time Series

Description

The function `tsdiff` generates the differenced series of a non-stationary time series.

Usage

tsdiff(x, lag = 1L, order = 1L, lag.D = 0L, order.D = 0L)

Value

The differences of x will be returned with all the attributes being carried over. Unlike the function diff, the output series by tsdiff has the same length as the original series by adding NA to those observations at the beginning of the series for which no differencing can be carried out.

Arguments

x

a univariate time series object or a numeric vector or matrix.

lag

number of lags for non-seasonal differencing. Default is 1.

order

order of non-seasonal differencing. Default is 1.

lag.D

number of lags for seasonal differencing. Default is 0.

order.D

order of seasonal differencing. Default is 0.

Author

Ka Yui Karl Wu

Details

The parameters lag and lag.D are only necessary if the lag difference for differencing is not 1 or \(\ell\), the seasonal cycle length, respectively. If order.D > 0 but lag.D is omitted, R will use the frequency of the series for this parameter.

See Also

Examples

Run this code
travellers_d <- tsdiff(x = airport$Travellers, order = 1, order.D = 1)
tsexplore(travellers_d, lag.max = 60)

Run the code above in your browser using DataLab