View source: R/widely_kmeans.R
widely_kmeans | R Documentation |
Given a tidy table of features describing each item, perform k-means
clustering using kmeans()
and retidy the data into
one-row-per-cluster.
widely_kmeans(tbl, item, feature, value, k, fill = 0, ...)
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 |
widely_hclust()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.