View source: R/widely_hclust.R
widely_hclust | R Documentation |
Reshape a table that represents pairwise distances into hierarchical clusters,
returning a table with item
and cluster
columns.
widely_hclust(tbl, item1, item2, distance, k = NULL, h = NULL)
tbl |
Table |
item1 |
First item |
item2 |
Second item |
distance |
Distance column |
k |
The desired number of groups |
h |
Height at which to cut the hierarchically clustered tree |
cutree
library(gapminder) library(dplyr) # Construct Euclidean distances between countries based on life # expectancy over time country_distances <- gapminder %>% pairwise_dist(country, year, lifeExp) country_distances # Turn this into 5 hierarchical clusters clusters <- country_distances %>% widely_hclust(item1, item2, distance, k = 8) # Examine a few such 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.