Created
May 16, 2014 21:28
-
-
Save ramhiser/5e1282a81abab5afd067 to your computer and use it in GitHub Desktop.
Create adjacency matrix from cluster labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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