Learn R Programming

tsforecast (version 1.3.0)

ts-functions: Extract Information of a Time Series

Description

The function `tsfreq` extract the frequency of a time series, while `tstime` extract the time periods in which the series data were observed, and `tstimegap` returns the time gap between the observations of a time series.

The function `tsname` can be used to extract or specify the name of a time series.

Usage

## Extract frequency of a time series
tsfreq(x)

## Extract observation time periods of a time series tstime(x)

## Extract time gaps between a time series' observations tstimegap(t)

## Get or set the name of a time series tsname(x, x.name = NULL)

## Copy Attributes from a Time Series to Another tsattrcopy(x, x.orig)

Value

For `tstime`, a list will be returned to the user with two elements: time (observation time) and frequnecy (observation frequency).

For `tsfreq`, R extracts the attribute `seasonal.cycle` from the time series object x.

For `tstimegap`, R calculates the time gap between the time periods stored in the vector t.

So, if x and t are consistent and refer to the data and time of the same time series, the results of `tsfreq` and `tstimegap` as well as the frequnecy element of `tstime` must be identical.

If x.name is NULL, the attribute series.name of x will be returned. Otherwise, the series will be returned with a new value for the attribute series.name specified by x.name.

For tsattrcopy, the function does the same as attributes. However, attributes only works if both x and x.orig share the same length, whereas tsattrcopy does not require this property and returns x with all the attributes originated from the series x.orig.

Arguments

x

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

t

a vector or list of time in which the series values were observed.

x.name

a new name for x. If the parameter is omitted, the current name of the time series will be returned to the user.

x.orig

a univariate time series object whose attributes will be transferred to x.

Author

Ka Yui Karl Wu

Details

To set a new name for a time series, the function must be assigned to an object. Otherwise, the new name will not be taken over.

See Also

Examples

Run this code
tsfreq(x = airport$Travellers)
tstime(x = airport$Travellers)
tstimegap(t = airport$Date)
airport$Travellers <- tsname(airport$Travellers, x.name = "Number of Travellers in Airport X")
tsname(airport$Travellers)
tsattrcopy(airport$Travellers[1:60], airport$Travellers)

Run the code above in your browser using DataLab