O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To perform hierarchical cluster analysis, follow these steps:

  1. Read the data and normalize it to the same scale. We will ignore the Country variable during scaling (as it is a categorical variable):
> proteinIntake <- read.csv("protein.csv") > head(proteinIntake)

 Here is how it will look:

> proteinIntakeScaled = as.data.frame(scale(proteinIntake[,-1]))> proteinIntakeScaled$Country =proteinIntake$Country
  1. Now use agglomerative hierarchical clustering to cluster the scaled protein intake data:
> hc = hclust(dist(proteinIntakeScaled, method="euclidean"), method="ward.D2")> hcCall:hclust(d = dist(proteinIntakeScaled, method ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required