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

  1. First, load the following packages:
library(cluster)library(factoextra)
  1. Compute clara with k = 4 and sample size (samples=5) on the scaled data frame and check the medoids:
> claraFit <- clara(proteinIntakeScaled, 4, samples=5)> claraFit$medoids

Here is how the code will look with our computation:

  1. Now visualize the result with a plot:
> fviz_cluster(claraFit)

The following figure shows the cluster plot of our computation:

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