View source: R/cluster_centroid.R
cluster_centroid | R Documentation |
This function allows to compute the centroid of a cluster in a R data frame
cluster_centroid(i, data, cluster_variable)
i |
an integer that represents the cluster number. |
data |
a R data frame (all columns are required to be numeric types). |
cluster_variable |
a character. This refers to the column name of the data frame representing the clusters. |
a vector of coordinates of the centroid of the cluster i.
Simon CORDE
Link to the author's github package repository: https://github.com/Redcart/helda
library(dplyr) # We create some cluster from k-means on the iris data set data <- iris %>% select(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width) result_kmeans <- kmeans(data, 3) data$cluster <- result_kmeans$cluster # We get the coordinates of the centroid of the second cluster result <- cluster_centroid(i = 2, data = data, cluster_variable = "cluster") result
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.