
Last chance! 50% off unlimited learning
Sale ends in
Various types of subsetting of a time series. Allows subsetting by index
values (unlike window
). Also allows extraction of the
values of a specific season or subset of seasons in each year. For example,
to extract all values for the month of May from a time series.
# S3 method for ts
subset(x, subset = NULL, month = NULL, quarter = NULL,
season = NULL, start = NULL, end = NULL, ...)# S3 method for msts
subset(x, subset = NULL, start = NULL, end = NULL,
...)
a univariate time series to be subsetted
optional logical expression indicating elements to keep;
missing values are taken as false. subset
must be the same length as
x
.
Numeric or character vector of months to retain. Partial matching on month names used.
Numeric or character vector of quarters to retain.
Numeric vector of seasons to retain.
Index of start of contiguous subset.
Index of end of contiguous subset.
Other arguments, unused.
If subset
is used, a numeric vector is returned with no ts
attributes. If start
and/or end
are used, a ts object is
returned consisting of x[start:end], with the appropriate time series
attributes retained. Otherwise, a ts object is returned with frequency equal
to the length of month
, quarter
or season
.
If character values for months are used, either upper or lower case may be
used, and partial unambiguous names are acceptable. Possible character
values for quarters are "Q1"
, "Q2"
, "Q3"
, and
"Q4"
.
# NOT RUN {
plot(subset(gas,month="November"))
subset(woolyrnq,quarter=3)
subset(USAccDeaths, start=49)
# }
Run the code above in your browser using DataLab