To perform cluster analysis using kmeans clustering, follow these steps:
-
First, load the protein.csv file and do some preprocessing to add row names as Country name and remove the Country variable before normalizing the data:
> proteinIntake <- read.csv("protein.csv")> rownames(proteinIntake)=proteinIntake$Country> proteinIntake$Country=NULL> proteinIntakeScaled = as.data.frame(scale(proteinIntake))
- Now use kmeans to cluster the scaled protein intake data:
> set.seed(22) ## To fix the random cluster initialization> kmFit = kmeans(proteinIntakeScaled, 4)> kmFit
Here is the K-means clustering indicative of the code: