\HeaderA{window}{Time Windows}{window}
\methaliasA{window.default}{window}{window.default}
\methaliasA{window.ts}{window}{window.ts}
\aliasA{window<\Rdash}{window}{window<.Rdash.}
\methaliasA{window<\Rdash.ts}{window}{window<.Rdash..ts}
\keyword{ts}{window}
\begin{Description}\relax
\code{window} is a generic function which
extracts the subset of the object \code{x}
observed between the times \code{start} and \code{end}. If a
frequency is specified, the series is then re-sampled at the new
frequency.
\end{Description}
\begin{Usage}
\begin{verbatim}
window(x, ...)
## S3 method for class 'ts':
window(x, ...)
## Default S3 method:
window(x, start = NULL, end = NULL,
      frequency = NULL, deltat = NULL, extend = FALSE, ...)

window(x, ...) <- value
## S3 replacement method for class 'ts':
window(x, start, end, frequency, deltat, ...) <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a time-series (or other object if not replacing values).
\item[\code{start}] the start time of the period of interest.
\item[\code{end}] the end time of the period of interest.
\item[\code{frequency, deltat}] the new frequency can be specified by either
(or both if they are consistent).
\item[\code{extend}] logical.  If true, the \code{start} and \code{end} values
are allowed to extend the series.  If false, attempts to extend the
series give a warning and are ignored.
\item[\code{...}] further arguments passed to or from other methods.
\item[\code{value}] replacement values.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The start and end times can be specified as for \code{\LinkA{ts}{ts}}. If
there is no observation at the new \code{start} or \code{end},
the immediately following (\code{start}) or preceding (\code{end})
observation time is used.

The replacement function has a method for \code{ts} objects, and
is allowed to extend the series (with a warning).  There is no default
method.
\end{Details}
\begin{Value}
The value depends on the method. \code{window.default} will return a
vector or matrix with an appropriate \code{\LinkA{tsp}{tsp}} attribute.

\code{window.ts} differs from \code{window.default} only in
ensuring the result is a \code{ts} object.

If \code{extend = TRUE} the series will be padded with \code{NA}s if
needed.
\end{Value}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{time}{time}}, \code{\LinkA{ts}{ts}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
window(presidents, 1960, c(1969,4)) # values in the 1960's
window(presidents, deltat=1)  # All Qtr1s
window(presidents, start=c(1945,3), deltat=1)  # All Qtr3s
window(presidents, 1944, c(1979,2), extend=TRUE)

pres <- window(presidents, 1945, c(1949,4)) # values in the 1940's
window(pres, 1945.25, 1945.50) <- c(60, 70)
window(pres, 1944, 1944.75) <- 0 # will generate a warning
window(pres, c(1945,4), c(1949,4), frequency=1) <- 85:89
pres
\end{ExampleCode}
\end{Examples}

