window
Window a Time Series

Description

Returns a time series with a new start, new end, and /or new frequency or new deltat. The data of this time series can be replaced with new values.

Usage

# Generic function.
window(x, ...)
## Default S3 method:
window(x, start = NULL, end = NULL, frequency = NULL, deltat = NULL,
    extend = FALSE, ...)
## S3 method for class 'ts':
window(x, ...)

# Generic function. window(x, ...) <- value ## S3 method for class 'ts': window(x, start, end, frequency, deltat, ...) <- value

Arguments

x univariate or multivariate time series, or a vector or matrix. If not a time series the default tsp parameters of start = 1, end = nrow(x) and frequency = 1 are used. Missing values (NA's) are allowed.
start new starting date for the series; if earlier than the starting date of x, no change is made on start when extend is FALSE. If extend is TRUE, NA's are prepended to extended time series. This can be either a single numeric value, or a length 2 integer vector giving the period and the position within the period. If start falls between two actual sampling times then the value of the later one is used.
end new ending date for the series; if later than the ending date of x, no change is made on end when extend is FALSE. If extend is TRUE, NA's are appended to extended time series. This can be either a single numeric value, or a length 2 integer vector giving the period and the position within the period. If end falls between two actual sampling times then the value of the earlier one is used.
frequency new observations frequency; that is, how many observations per sampling period. The new frequency must be divided exactly by the frequency of x. Otherwise, the frequency is not changed.
deltat new argument to be provided instead of frequency. This represents the fraction of the sampling period between successive observations; e.g., monthly data has deltat=1/12. Only one of frequency or deltat should be provided. Note that the calculated frequency must be divided exactly by the frequency of x. Otherwise, the deltat is not changed.
extend a logical value to indicate if start and/or end can be extended. See start and end argument description.
... other arguments pass to or from methods.
value a vector of new data values to replace the window-ed time series. The length of it must be identical or sub-multiplied to the length of window-ed time series (after any extension). The values are replaced repeatedly in sub-multiple case.

Details

window() is a generic function and has a hidden default method and a hidden method for class "ts".
The assignment function window<- is generic and has only a hidden method for class "ts".
Value
window.default()returns a vector or matrix with the attribute "tsp" which contains the new start, new end, and new frequency.
window.ts()returns a time series with a new start, new end, and /or new frequency or new deltat.
The assignment function window<-.ts() replaces the values of time series with new values.
References
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language: A Programming Environment for Data Analysis and Graphics. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software.
See Also
ts, tsp, time.
Examples
window(Sdatasets::freeny.y, start=c(1963, 3), end=c(1967, 2))
window(Sdatasets::freeny.y, start=c(1963, 3), end=c(1967, 2), frequency=2)

window(Sdatasets::freeny.y, start=1960, end=c(1975, 2), extend=TRUE)

local.freeny <- Sdatasets::freeny.y window(local.freeny, start=1963.25, end=1963.50) <- c(6.90, 6.95) local.freeny

# Example for window.default window(matrix(1:12, nrow=3), start=2 , end=3)

Package stats version 6.1.4-13
Package Index