Skip to content

Instantly share code, notes, and snippets.

@ramhiser
Created May 16, 2014 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramhiser/5e1282a81abab5afd067 to your computer and use it in GitHub Desktop.
Save ramhiser/5e1282a81abab5afd067 to your computer and use it in GitHub Desktop.
Create adjacency matrix from cluster labels
library(clusteval)
adjacency_matrix <- function(cluster_labels, names=NULL, force_symmetric=FALSE) {
adj_matrix <- diag(length(cluster_labels))
adj_matrix[lower.tri(adj_matrix)] <- clusteval::comembership(cluster_labels)
if (force_symmetric) {
adj_matrix <- adj_matrix + t(adj_matrix)
}
diag(adj_matrix) <- 0
if (!is.null(names))
rownames(adj_matrix) <- colnames(adj_matrix) <- names
adj_matrix
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment