#' Printing the summary of k-means clustering
#'
#' \code{print} method for class \code{"kMeansSummary"}.
#'
#' @param x an object of class \code{"kMeansSummary"}, usually a result of the
#' call \code{summary.kMeans}.
#' @param ... further arguments passed to or from other methods.
#'
#' @return The method prints the within sum of squares, the total within sum
#' of squares, the between sum of squares and the total sum of squares that result
#' from calling \code{summary.kMeans}.
#' @export
#' @examples
#' # create example data set
#' X <- rbind(matrix(rnorm(50, sd = 0.5), ncol = 2),
#' matrix(rnorm(50, mean = 1, sd = 0.5), ncol = 2))
#'
#' # perform k-means algorithm
#' result <- kMeansLloyd(x = X, centroids = 2, nStart = 2)
#'
#' # summarise result
#' clustSum <- summary(result)
#' print(clustSum)
print.kMeansSummary <- function(x, ...){
cat("Statistics of the cluster analysis:\n")
cat("\nSum of Squares Within:", x$withinSS)
cat("\nTotal Sum of Squares Within:", x$withinTot)
cat("\nSum of Squares Between:", x$betweenSS)
cat("\nTotal Sum of Squares:", x$totalSS)
cat("\nProportion of explained variance (betweenSS / totSS): ",
x$betweenSS / x$totalSS * 100, "%", "\n", sep = "")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.