cluster_hclust: Hierarchical clustering

View source: R/clu_hclust.R

cluster_hclustR Documentation

Hierarchical clustering

Description

Agglomerative hierarchical clustering using stats::hclust.

Usage

cluster_hclust(
  k = 2,
  h = NULL,
  method = "ward.D2",
  dist = "euclidean",
  scale = TRUE
)

Arguments

k

number of clusters to cut the tree (default 2)

h

height to cut the tree (optional; if provided, overrides k)

method

linkage method passed to stats::hclust (default "ward.D2")

dist

distance method passed to stats::dist (default "euclidean")

scale

logical; whether to scale data before distance (default TRUE)

Details

Computes a distance matrix (optionally after scaling) and builds a dendrogram. Clusters are obtained by cutting the tree with k (number of clusters) or h (height).

Value

returns a hierarchical clustering object.

References

Johnson, S. C. (1967). Hierarchical clustering schemes. Psychometrika.

Examples

data(iris)
model <- cluster_hclust(k = 3)
model <- fit(model, iris[,1:4])
clu <- cluster(model, iris[,1:4])
table(clu)

daltoolbox documentation built on Feb. 10, 2026, 9:06 a.m.