cluster_centroid: Centroid of a cluster

Description Usage Arguments Value Author(s) References Examples

View source: R/cluster_centroid.R

Description

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

Usage

1
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.

Author(s)

Simon CORDE

References

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

Examples

1
2
3
4
5
6
7
8
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

helda documentation built on Jan. 6, 2021, 5:09 p.m.