\Header{cutree}{Cut a tree into groups of data}
\keyword{multivariate}{cutree}
\keyword{cluster}{cutree}
\begin{Description}\relax
Cuts a tree, e.g., as resulting from \code{\Link{hclust}}, into several
groups either by specifying the desired number of groups or the cut
height.\end{Description}
\begin{Usage}
\begin{verbatim}
cutree(tree, k=NULL, h=NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{tree}] a tree as produced by \code{\Link{hclust}}
\item[\code{k}] an integer scalar or vector with the desired number of groups
\item[\code{h}] numeric scalar or vector with heights where the tree should
be cut.
\end{ldescription}

At least one of \code{k} or \code{h} must be specified, \code{k}
overrides \code{h} if both are given.\end{Arguments}
\begin{Value}
\code{cutree} returns a vector with group memberships if \code{k} or
\code{h} are scalar, otherwise a matrix with group meberships is returned
where each column corresponds to the elements of \code{k} or \code{h},
respectively (which are also used as column names).\end{Value}
\begin{SeeAlso}\relax
\code{\Link{hclust}}\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
require(mva)
data(USArrests)

hc <- hclust(dist(USArrests))

cutree(hc, k=1:5)#k = 1 is trivial
cutree(hc, h=250)

## Compare the 2 and 3 grouping:
g24 <- cutree(hc, k = c(2,4))
table(g24[,"2"], g24[,"4"])

\end{ExampleCode}
\end{Examples}

