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 it works...

We can determine the number of clusters from the dendrogram in the preceding figure. In the first step, we decided that there should be four clusters within the tree using the k=4 attribute in the cutree function. Besides using the number of clusters to cut the tree, you can also specify the height as the cut tree parameter.

Next, we use the table function to count the number of data within each cluster and we find that most of the data is in cluster 2. Lastly, we draw red rectangles around the clusters to show how the data is categorized into the four clusters with the rect.hclust function.

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