Function to flatten diagonally symmetrical matrix
########################## flattenCorrMatrix <- function(cormat) { ut <- upper.tri(cormat) data.frame( row = rownames(cormat)[row(cormat)[ut]], column = rownames(cormat)[col(cormat)[ut]], cor =(cormat)[ut], #p = pmat[ut] ) }
Function to flatten diagonally symmetrical matrix
function (data, method = "pearson", linkage = "average", absolute = FALSE) { if (!is.matrix(data) & !is.data.frame(data)) { stop("data must be a matrix or data frame.") } if (match(method, c("pearson", "spearman", "kendall"))) { dist <- as.dist(cor.dist(data, methods = method, absolute = absolute)) } else if (match(method, c("euclidean", "maximum", "manhattan", "canberra", "binary", "minkowski"))) { dist <- dist(data, method = method) } else if (match(method, c("uncentered"))) { dist <- as.dist(uncent.cordist(data)) } else { stop("method must be a similarity or distance measure as described in cor(), dist(), or uncent.cordist.") } hclust(d = dist, method = linkage) }