\Header{subset}{Subsetting Vectors and Data Frames}
\methalias{subset.data.frame}{subset}
\methalias{subset.default}{subset}
\keyword{manip}{subset}
\begin{Description}\relax
Return subsets of vectors or data frames which meet conditions.\end{Description}
\begin{Usage}
\begin{verbatim}
subset(x, ...)
subset.default(x, subset, ...)
subset.data.frame(x, subset, select, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] object to be subsetted
\item[\code{...}] how to subset, depends on object
\item[\code{subset}] logical expression
\item[\code{select}] expression, indicating variables to select from a
data frame
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
For ordinary vectors, the result is simply
\code{x[subset \& !is.na(subset)]}.

For dataframes, the \code{subset} argument works similarly on the
rows.  Note that \code{subset} will be evaluated in the dataframe.

The \code{select} argument exists only for dataframes.  It works by
first replacing variable names in the selection expression with the
corresponding column numbers in the dataframe and then using the
resulting integer vector to index the columns.  This allows the use
of the standard indexing conventions so that for examples ranges of
variables can be specified easily.\end{Details}
\begin{Value}
Selected rows and columns of the object \code{x}.\end{Value}
\begin{Author}\relax
Peter Dalgaard\end{Author}
\begin{SeeAlso}\relax
\code{\Link{[}}, 
\code{\Link{transform}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
data(airquality)
subset(airquality, Temp > 80, select = c(Ozone, Temp))
subset(airquality, Day == 1, select = -Temp)
subset(airquality, select = Ozone:Wind)

attach(airquality)
subset(Ozone, Temp > 80)
\end{ExampleCode}
\end{Examples}

