library(cluster)
x <- rbind(cbind(rnorm(10,0,0.5), rnorm(10,0,0.5)),
cbind(rnorm(15,5,0.5), rnorm(15,5,0.5)))
clust <- optimal.k(x, 20, plot=TRUE, cluster=TRUE)
plot(silhouette(clust$model), col = c('red', 'green'))
plot(clust$model, which.plots=1, main='K-Medoid fit')
# Extract multivariate and univariate mediods (class centers)
clust$model$medoids
pam(x[,1], 1)$medoids
# join clusters to data
x <- data.frame(x, k=clust$model$clustering)
Run the code above in your browser using DataLab