Skip to contents

Function to assign a cluster to each observation of the entire dataset by selecting the closest medoid

Usage

assign_cluster(
  data,
  metric,
  medoids,
  dist_matrix = NULL,
  type = "hard",
  m = 2,
  data_medoids = NULL,
  return_distMatrix = FALSE,
  return_data_medoids = FALSE
)

Arguments

data

Entire data.frame

metric

A character specifying a predefined dissimilarity metric (like "euclidean" or "manhattan") or a self-defined dissimilarity function. Defaults to "euclidean". Will be passed as argument method to dist, so check ?proxy::dist for full details.

medoids

Medoids of the obtained clustering solution for the data sample

dist_matrix

Optional dissimilarity matrix (defaults to NULL)

type

One of c("hard","fuzzy"), specifying the type of clustering to be performed.

m

Fuzziness exponent (only for type = "fuzzy"), which has to be a numeric of minimum 1. Defaults to 2.

data_medoids

data.frame with variable information of medoids

return_distMatrix

Indicator if the distances to the cluster medoids should be returned. Defaults to FALSE.

return_data_medoids

Indicator if the medoid data should be returned. Defaults to FALSE.

Value

List with information on cluster results (medoid, cluster assignment, average distance to the closest medoid (weighted average distance to the closest medoid in case of fuzzy clustering))