# Determine number of clusters wss <- (nrow(input_output_10000_2)-1)*sum(apply(input_output_10000_2,2,var)) for (i in 2:15) wss[i] <- sum(kmeans(input_output_10000_2, centers=i)$withinss) plot(1:15, wss, type="b", xlab="Number of Clusters", ylab="Within groups sum of squares") # K-Means Cluster Analysis fit <- kmeans(input_output_10000_2, 3) # 3 cluster solution # get cluster means aggregate(input_output_10000_2,by=list(fit$cluster),FUN=mean) # append cluster assignment input_output_10000_2 <- data.frame(input_output_10000_2, fit$cluster)