\Header{Extract.factor}{Extract or Replace Parts of a Factor}
\alias{[.factor}{Extract.factor}
\alias{[<\Rdash.factor}{Extract.factor}
\keyword{category}{Extract.factor}
\begin{Description}\relax
Extract or replace subsets of factors.\end{Description}
\begin{Usage}
\begin{verbatim}
x[i, drop = FALSE]

x[i] <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a factor
\item[\code{i}] a specification of indices -- see \code{\Link{Extract}}.
\item[\code{drop}] logical.  If true, unused levels are dropped.
\item[\code{value}] character: a set of levels.  Factor values are coerced to
character.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
When unused levels are dropped the ordering of the remaining levels is
preserved.

If \code{value} is not in \code{levels(x)}, a missing value is
assigned with a warning.

Any \code{\Link{contrasts}} assigned to the factor are preserved
unless \code{drop=TRUE}.\end{Details}
\begin{Value}
A factor with the same set of levels as \code{x} unless \code{drop=TRUE}.\end{Value}
\begin{SeeAlso}\relax
\code{\Link{factor}}, \code{\Link{Extract}}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
## following example(factor)
(ff <- factor(substring("statistics", 1:10, 1:10), levels=letters))
ff[, drop=TRUE]
factor(letters[7:10])[2:3, drop = TRUE]
\end{ExampleCode}
\end{Examples}

