Learn R Programming

lowmemtkmeans (version 0.1.4)

nearest_cluster: Allocates each rw (observation) in data to the nearest cluster centre.

Description

For each observation the euclidean distance to each of the cluster centres is calculated and cluster with the smallest distance is return for that observation.

Usage

nearest_cluster(data, centres)

Value

vector of cluster allocations, n values ranging from 1 to k.

Arguments

data

a matrix (n x m) to be clustered

centres

matrix of cluster means (k x m), where k is the number of clusters.

Examples

Run this code
iris_mat <- as.matrix(iris[,1:4])
centres<- tkmeans(iris_mat, 3 , 0.2, c(1,1,1,1), 1, 10, 0.001)
nearest_cluster(iris_mat, centres)

Run the code above in your browser using DataLab