Learn R Programming

rcppmlpackexamples (version 0.0.1)

kMeans: Run a k-means clustering analysis

Description

Run a k-means clustering analysis, returning a list of cluster assignments

Usage

kMeans(data, clusters)

Value

A list with cluster assignments

Arguments

data

A matrix of data values

clusters

An integer specifying the number of clusters

Details

This function performs a k-means clustering analysis on the given data set.

Examples

Run this code
x <- rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
           matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
colnames(x) <- c("x", "y")
cl <- kMeans(x, 2)

data(trees, package="datasets")
cl2 <- kMeans(t(trees),3)

Run the code above in your browser using DataLab