Learn R Programming

helda (version 1.1.5)

cluster_centroid: Centroid of a cluster

Description

This function allows to compute the centroid of a cluster in a R data frame

Usage

cluster_centroid(i, data, cluster_variable)

Arguments

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.

Value

a vector of coordinates of the centroid of the cluster i.

References

Link to the author's github package repository: https://github.com/Redcart/helda

Examples

Run this code
# NOT RUN {
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
# }

Run the code above in your browser using DataLab