# NOT RUN {
# Load and scale data
data("USArrests")
df <- scale(USArrests)
# Enhanced k-means clustering
# nboot >= 500 is recommended
res.km <- eclust(df, "kmeans", nboot = 2)
# Silhouette plot
fviz_silhouette(res.km)
# Optimal number of clusters using gap statistics
res.km$nbclust
# Print result
 res.km
 
# }
# NOT RUN {
 # Enhanced hierarchical clustering
 res.hc <- eclust(df, "hclust", nboot = 2) # compute hclust
  fviz_dend(res.hc) # dendrogam
  fviz_silhouette(res.hc) # silhouette plot
# }
# NOT RUN {
 
# }
Run the code above in your browser using DataLab