cutree
Create Groups from Hierarchical Clustering

Description

Returns a vector of group numbers for the observations that were clustered. Specify either the number of groups desired or a clustering height.

Usage

cutree(tree, k = NULL, h = NULL)

Arguments

tree a hierarchical clustering tree structure of class "hclust". It is commonly the output of the hclust function.
k the desired number of groups. Must be between 1 and the row number of the "merge" component of tree. If k is a vector of integers, the output will be a matrix with a column for each value in k. The default is NULL. Either k or h must be non-NULL, if both are non-NULL, then k is used and h is ignored.
h the height at which to cut tree to produce the groups. Groups are defined by the structure of the tree above the cut. If h is a vector of numbers, the output will be a matrix with a column for each value in h. The default is NULL. Either k or h must be non-NULL, if both are non-NULL then k is used and h is ignored.
Value
For scalar k or h, cutree returns a vector with as many elements as there are leaves in the tree. The ith element of the vector gives the group number to which individual i is assigned. For vector k or h (of length more than 1), cutree returns a matrix with a column of group numbers for each value in k or h.
Differences between Spotfire Enterprise Runtime for R and Open-source R
The group numbering might be different between Spotfire Enterprise Runtime for R and open-source R, but the group memberships are the same.
In open-source R, when k is NULL, and if the "height" component of tree is not sorted, cutree is stopped. Spotfire Enterprise Runtime for R sorts the "height" component to ensure "height" is ordered as increasing.
References
Becker, R. A., Chambers, J. M., and Wilks, A. R. 1988. The New S Language: A Programming Environment for Data Analysis and Graphics. Pacific Grove, CA: Wadsworth & Brooks/Cole Advanced Books and Software.
See Also
dist, hclust
Examples
hc <- hclust(dist(c(12, 2, 5, 4, 3)))
cutree(hc, k=5)

vote.cl <- hclust(dist(Sdatasets::votes.repub)) group <- cutree(vote.cl, k=5) # produce 5 groups Sdatasets::state.name[group==1]

Package stats version 6.1.4-13
Package Index