Skip to contents

This function finds the medoids from a distance matrix. The medoid is the object that minimizes the sum of distances to all other objects. This function takes advantage of the RcppParallel package to compute the medoids in parallel.

Usage

find_medoids(D, memberships = NULL)

Arguments

D

An object of class stats::dist.

memberships

A factor specifying the cluster memberships of the objects.

Value

A named integer vector specifying the indices of the medoids.

Examples

D <- stats::dist(iris[, 1:4])
find_medoids(D)
#> [1] 62
memberships <- as.factor(rep(1:3, each = 50L))
find_medoids(D, memberships)
#>   1   2   3 
#>   8  97 113