run_kmeans {opm}R Documentation

Conduct k-means partitioning

Description

Run a k-means partitioning analysis. This function is used by discrete in ‘gap’ mode to automatically determine the range of ambiguous data. If applied to such one-dimensional data, it uses an exact algorithm from the Ckmeans.1d.dp package.

Usage

  ## S4 method for signature 'matrix,numeric'
run_kmeans(object, k, cores = 1L, nstart = 10L, ...)
  ## S4 method for signature 'numeric,numeric'
run_kmeans(object, k, cores = 1L)

Arguments

object

Numeric vector or matrix.

k

Numeric vector. Number of clusters requested.

nstart

Numeric scalar. Ignored if ‘Ckmeans.1d.dp’ is called. Otherwise passed to kmeans from the stats package.

cores

Numeric scalar indicating the number of cores to use.

...

List of optional arguments passed to kmeans from the stats package.

Value

S3 object of class kmeanss, basically a named list of kmeans objects.

References

Wang, H., Song, M. 2011 Ckmeans.1d.dp: Optimal k-means clustering in one dimension by dynamic programming. The R Journal 3, p. 29–33.

See Also

stats::kmeans Ckmeans.1d.dp::Ckmeans.1d.dp

Other kmeans-functions: borders, calinski, hist.Ckmeans.1d.dp, hist.kmeans, hist.kmeanss, plot.kmeanss, to_kmeans,

Examples

x <- as.vector(extract(vaas_4, as.labels = NULL, subset = "A"))
summary(x.km <- run_kmeans(x, k = 1:10)) # => 'kmeanss' object
##    Length Class  Mode
## 1  9      kmeans list
## 2  9      kmeans list
## 3  9      kmeans list
## 4  9      kmeans list
## 5  9      kmeans list
## 6  9      kmeans list
## 7  9      kmeans list
## 8  9      kmeans list
## 9  9      kmeans list
## 10 9      kmeans list
stopifnot(inherits(x.km, "kmeanss"), length(x.km) == 10)
stopifnot(sapply(x.km, class) == "kmeans", names(x.km) == 1:10)

[Package opm version 1.3.63 Index]