widely_kmeans {widyr} | R Documentation |
Cluster items based on k-means across features
Description
Given a tidy table of features describing each item, perform k-means
clustering using kmeans()
and retidy the data into
one-row-per-cluster.
Usage
widely_kmeans(tbl, item, feature, value, k, fill = 0, ...)
Arguments
tbl |
Table |
item |
Item to cluster (as a bare column name) |
feature |
Feature column (dimension in clustering) |
value |
Value column |
k |
Number of clusters |
fill |
What to fill in for missing values |
... |
Other arguments passed on to |
See Also
Examples
library(gapminder)
library(dplyr)
clusters <- gapminder %>%
widely_kmeans(country, year, lifeExp, k = 5)
clusters
clusters %>%
count(cluster)
# Examine a few clusters
clusters %>% filter(cluster == 1)
clusters %>% filter(cluster == 2)
[Package widyr version 0.1.5 Index]