1% File src/library/stats/man/window.Rd 2% Part of the R package, https://www.R-project.org 3% Copyright 1995-2007 R Core Team 4% Distributed under GPL 2 or later 5 6\name{window} 7\title{Time (Series) Windows} 8\alias{window} 9\alias{window.default} 10\alias{window.ts} 11\alias{window<-} 12\alias{window<-.ts} 13 14\usage{ 15window(x, \dots) 16\method{window}{ts}(x, \dots) 17\method{window}{default}(x, start = NULL, end = NULL, 18 frequency = NULL, deltat = NULL, extend = FALSE, ts.eps = getOption("ts.eps"), \dots) 19 20window(x, \dots) <- value 21\method{window}{ts}(x, start, end, frequency, deltat, \dots) <- value 22} 23\arguments{ 24 \item{x}{a time-series (or other object if not replacing values).} 25 \item{start}{the start time of the period of interest.} 26 \item{end}{the end time of the period of interest.} 27 \item{frequency, deltat}{the new frequency can be specified by either 28 (or both if they are consistent).} 29 \item{extend}{logical. If true, the \code{start} and \code{end} values 30 are allowed to extend the series. If false, attempts to extend the 31 series give a warning and are ignored.} 32 \item{ts.eps}{time series comparison tolerance. Frequencies are 33 considered equal if their absolute difference is less than 34 \code{ts.eps}.} 35 \item{\dots}{further arguments passed to or from other methods.} 36 \item{value}{replacement values.} 37} 38\description{ 39 \code{window} is a generic function which 40 extracts the subset of the object \code{x} 41 observed between the times \code{start} and \code{end}. If a 42 frequency is specified, the series is then re-sampled at the new 43 frequency. 44} 45\details{ 46 The start and end times can be specified as for \code{\link{ts}}. If 47 there is no observation at the new \code{start} or \code{end}, 48 the immediately following (\code{start}) or preceding (\code{end}) 49 observation time is used. 50 51 The replacement function has a method for \code{ts} objects, and 52 is allowed to extend the series (with a warning). There is no default 53 method. 54} 55\value{ 56 The value depends on the method. \code{window.default} will return a 57 vector or matrix with an appropriate \code{\link{tsp}} attribute. 58 59 \code{window.ts} differs from \code{window.default} only in 60 ensuring the result is a \code{ts} object. 61 62 If \code{extend = TRUE} the series will be padded with \code{NA}s if 63 needed. 64} 65\references{ 66 Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) 67 \emph{The New S Language}. 68 Wadsworth & Brooks/Cole. 69} 70\seealso{\code{\link{time}}, \code{\link{ts}}.} 71\examples{ 72window(presidents, 1960, c(1969,4)) # values in the 1960's 73window(presidents, deltat = 1) # All Qtr1s 74window(presidents, start = c(1945,3), deltat = 1) # All Qtr3s 75window(presidents, 1944, c(1979,2), extend = TRUE) 76 77pres <- window(presidents, 1945, c(1949,4)) # values in the 1940's 78window(pres, 1945.25, 1945.50) <- c(60, 70) 79window(pres, 1944, 1944.75) <- 0 # will generate a warning 80window(pres, c(1945,4), c(1949,4), frequency = 1) <- 85:89 81pres 82} 83\keyword{ts} 84