# cutree

##### Cut a Tree into Groups of Data

Cuts a tree, e.g., as resulting from `hclust`

, into several
groups either by specifying the desired number(s) of groups or the cut
height(s).

- Keywords
- multivariate, cluster

##### Usage

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

##### Arguments

- tree
a tree as produced by

`hclust`

.`cutree()`

only expects a list with components`merge`

,`height`

, and`labels`

, of appropriate content each.- k
an integer scalar or vector with the desired number of groups

- h
numeric scalar or vector with heights where the tree should be cut.

##### Details

Cutting trees at a given height is only possible for ultrametric trees (with monotone clustering heights).

##### Value

`cutree`

returns a vector with group memberships if `k`

or
`h`

are scalar, otherwise a matrix with group memberships is returned
where each column corresponds to the elements of `k`

or `h`

,
respectively (which are also used as column names).

##### References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
*The New S Language*.
Wadsworth & Brooks/Cole.

##### See Also

`hclust`

, `dendrogram`

for cutting trees themselves.

##### Examples

`library(stats)`

```
# NOT RUN {
hc <- hclust(dist(USArrests))
cutree(hc, k = 1:5) #k = 1 is trivial
cutree(hc, h = 250)
## Compare the 2 and 4 grouping:
g24 <- cutree(hc, k = c(2,4))
table(grp2 = g24[,"2"], grp4 = g24[,"4"])
# }
```

*Documentation reproduced from package stats, version 3.6.0, License: Part of R 3.6.0*