Extract the hierarchical structure of the nodes in a dendrogram or cluster

风流意气都作罢 提交于 2019-12-04 09:55:52

First I find all subtrees (i.e structure) that uses a node. In your example, there would be 9 nodes.

subtrees <- partition_leaves(dend15)
leaves <- subtrees[[1]]   # assume top node is used by all subtrees

I make a helper function to find route for each leaf, and apply it to all leaves.

pathRoutes <- function(leaf) {
  which(sapply(subtrees, function(x) leaf %in% x))
}

paths <- lapply(leaves, pathRoutes)

The raw output in list form, where each list element is the structure for an end node / leaf

> paths
[[1]]
[1] 1 2 3

[[2]]
[1] 1 2 4

[[3]]
[1] 1 5 6

[[4]]
[1] 1 5 7 8

[[5]]
[1] 1 5 7 9
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!