Annotate data frame with clusters

annotate_clusters(df, cluster_labels, long = TRUE, selected_clusters = NULL)

Arguments

df

a data frame

cluster_labels

list of cluster labels, automatically converted to factor.

long

if TRUE, returned data frame will be in long format. See details for spec. Default is TRUE.

selected_clusters

optional cluster labels to filter

Value

a wide or long data frame

Details

Long data frame will have columns: Cluster, Measurement and Value.

Examples

dmat <- compute_dmat(iris, "euclidean", TRUE, c("Petal.Length", "Sepal.Length"))
res <- compute_clusters(dmat, "complete")
cluster_labels <- cut_clusters(res, 2)
annotated_data <- annotate_clusters(iris[, c("Petal.Length", "Sepal.Length")], cluster_labels)
head(annotated_data)
#> # A tibble: 6 × 3
#>   Cluster Measurement  Value
#>   <fct>   <chr>        <dbl>
#> 1 1       Petal.Length   1.4
#> 2 1       Sepal.Length   5.1
#> 3 1       Petal.Length   1.4
#> 4 1       Sepal.Length   4.9
#> 5 1       Petal.Length   1.3
#> 6 1       Sepal.Length   4.7