A practical tutorial on clustering in R covering three main algorithms: k-means, Partitioning Around Medoids (PAM), and hierarchical clustering. Includes working R code using the UCI wine dataset and World Bank country data. Covers how to choose the number of clusters using Hartigan's Rule, the Gap statistic, elbow method, and silhouette scores. Also discusses linkage methods for hierarchical clustering, visualization techniques including dendrograms and world maps, and package recommendations for scaling (fastcluster, ClusterR, tidyclust) and reproducibility (renv).
Table of contents
What is clustering?Popular clustering methodsHow to perform k-means clustering in RHow to cluster categorical data in R using Partitioning Around Medoids (PAM)How to perform hierarchical clustering in RConclusionFrequently asked questions about clustering in R134 Impressions