Search code examples
rdendrogramhclust

How can we put label of hclust in table according to clusters formed in dendogram


I have a dendogram with clusters having many leaf nodes/labels How can I put these labels of hclust in a table row wise according to the clusters formed using R


Solution

  • You need to access the data stored in your rect.hclust object, along these lines:

    obj <- rect.hclust(my_matrix, k = n)
    str(obj)
    

    By inspecting obj with str you will find a list of all the variables grouped by cluster. You can export these into a tabular form, for example by using lapply:

    labels <- lapply(obj, paste0, collapse = ",")