Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use hclust() and plot the output from it. This can require a fair bit of
data preprocessing. For this example, we’ll first take a subset of the
countries data set from the year
2009. For simplicity, we’ll also drop all rows that contain an NA, and then select a random 25 of the
remaining rows:
library(gcookbook)# For the data set# Get data from year 2009c2<-subset(countries,Year==2009)# Drop rows that have any NA valuesc2<-c2[complete.cases(c2),]# Pick out a random 25 countries# (Set random seed to make this repeatable)set.seed(201)c2<-c2[sample(1:nrow(c2),25),]c2Name Code Year GDP laborrate healthexp infmortality6731Mongolia MNG20091690.417072.974.1982627.81733Canada CAN200939599.041867.84379.760845.2...5966Macedonia,FYR MKD20094510.238054.0313.6897110.610148Turkmenistan TKM20093710.453668.077.0695548.0