\Header{window}{Time Windows}
\methalias{window.default}{window}
\methalias{window.ts}{window}
\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, ...)
window.default(x, start = NULL, end = NULL,
               frequency = NULL, deltat = NULL, extend = FALSE, ...)
window.ts(x, start = NULL, end = NULL,
          frequency = NULL, deltat = NULL, extend = FALSE, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a time-series or other object.
\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.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The start and end times can be specified as for \code{\Link{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.\end{Details}
\begin{Value}
The value depends on the method. \code{window.default} will return a
vector or matrix with an appropriate \code{\Link{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} if
needed.\end{Value}
\begin{SeeAlso}\relax
\code{\Link{time}}, \code{\Link{ts}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(presidents)
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)
\end{ExampleCode}
\end{Examples}

