Description Usage Arguments Value Examples
View source: R/functions_clusteringKmeans.R
perform kmeans clustering on matrix rows and return reordered matrix along with order matched cluster assignments clusters are sorted using hclust on centers the contents of each cluster are sorted using hclust
1 2 3 4 5 6 | clusteringKmeansNestedHclust(
mat,
nclust,
within_order_strategy = c("hclust", "sort")[2],
seed = NULL
)
|
mat |
A wide format matrix |
nclust |
the number of clusters |
within_order_strategy |
one of "hclust" or "sort". if hclust, hierarchical clustering will be used. if sort, a simple decreasing sort of rosSums. |
seed |
passed to set.seed() to allow reproducibility |
data.table with 2 columns of cluster info. id column corresponds with input matrix rownames and is sorted within each cluster using hierarchical clusering group column indicates cluster assignment
1 2 3 4 5 6 7 8 9 | dt = data.table::copy(CTCF_in_10a_profiles_dt)
mat = data.table::dcast(dt, id ~ sample + x, value.var = "y" )
rn = mat$id
mat = as.matrix(mat[,-1])
rownames(mat) = rn
clust_dt = clusteringKmeansNestedHclust(mat, nclust = 3)
dt = merge(dt, clust_dt)
dt$id = factor(dt$id, levels = clust_dt$id)
dt[order(id)]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.