kclusters_simple: Simple k-Means for 2 variable clustering

View source: R/kclusters.R

kclusters_simpleR Documentation

Simple k-Means for 2 variable clustering

Description

A utilization of the kmeans function to simplify k-means clustering of 2 variables.

Usage

kclusters_simple(x, y, k, ...)

Arguments

x

Formula. An expression of the form y ~ x where x and y are the variables to use for clustering.

k

Integer. The number of clusters to group the data into.

See Also

stats::kmeans

Examples

# Use k-means to cluster football/soccer players by height and weight.
data(futbol)
kclusters(wt_lbs ~ ht_inches, data = futbol, k = 2)

# Include this data in the original data and plot it
futbol <- mutate(futbol, cluster = kclusters(wt_lbs ~ ht_inches, data = futbol, k = 2))
xyplot(wt_lbs ~ ht_inches, data = futbol, groups = cluster)

# We can compare the clustering to the actual
xyplot(wt_lbs ~ ht_inches, data = futbol, groups = league)


mobilizingcs/mobilizr documentation built on Feb. 17, 2024, 7:49 p.m.