\HeaderA{Extract.factor}{Extract or Replace Parts of a Factor}{Extract.factor}
\aliasA{[.factor}{Extract.factor}{[.factor}
\aliasA{[<\Rdash.factor}{Extract.factor}{[<.Rdash..factor}
\aliasA{[[.factor}{Extract.factor}{[[.factor}
\keyword{category}{Extract.factor}
\begin{Description}\relax
Extract or replace subsets of factors.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'factor':
x[..., drop = FALSE]
## S3 method for class 'factor':
x[[...]]
## S3 replacement method for class 'factor':
x[...] <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a factor
\item[\code{...}] a specification of indices -- see \code{\LinkA{Extract}{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{\LinkA{contrasts}{contrasts}} assigned to the factor are preserved
unless \code{drop=TRUE}.

The \code{[[} method supports argument \code{exact}.
\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{\LinkA{factor}{factor}}, \code{\LinkA{Extract}{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}

