R package Ckmeans.1d.dp. A fast dynamic programming algorithm for optimal univariate k-means clustering. The algorithm minimizes the sum of squares of within-cluster distances. As an alternative to heuristic k-means algorithms, this method guarantees optimality and reproducibility. Its advantage in efficiency and accuracy over heuristic k-means clustering is increasingly pronounced as the number of clusters k increases.