forecast (version 3.08)

subset.ts: Subsetting a time series

Description

The main purpose of this function is to extract the values of a specific season in each year. For example, to extract all values for the month of May from a time series.

Usage

## S3 method for class 'ts':
subset(x, subset=NULL, month=NULL, quarter=NULL, season=NULL, ...)

Arguments

x
a univariate time series to be subsetted
subset
optional logical expression indicating elements to keep; missing values are taken as false.
month
Character list of months to retain. Partial matching on month names used.
quarter
Numeric list of quarters to retain.
season
Numeric list of seasons to retain.
...
Other arguments, unused.

Value

  • If one season per year is extracted, then a ts object is returned with frequency 1. Otherwise, a numeric vector is returned with no ts attributes.

See Also

subset

Examples

Run this code
plot(subset(gas,month="November"))
subset(woolyrnq,quarter=3)

Run the code above in your browser using DataCamp Workspace