I'm using agnes to group terms that frequently appear with one another in a set of documents. I get a dendrogram which verifies that things are working as expected. From this, I'd like to to retrieve the cluster of each member. I'm using cutree to cut the tree at a specified height, but it is returning one extra cluster, I'm not sure why.

[1] 132
length(cutree(flex75, h = 1.5))
[1] 133

It occurs for varying heights, even up to h = max(flex75$height) and all clusters = 1. So I cannot bind the labels to their clusters.


I found the issue to be when I reorder flex75$height to be in ascending order (I was previously receiving an error that: the 'height' component of 'tree' is not sorted (increasingly)). I was also reordering the $order and $order.lab components using the $height order, and turns out that height is of length n-1 and order/order.lab is of length n.

My question now is: What is the relationship between the agnes object's $height vector, and the $order/$order.lab vectors? Can I permute the heights, as I have, and feed that object into cutree? Should any of the object's other properties be correspondingly changed?


1 Answer 1


I found an answer in a related post here. Another user was getting a similar error about ordering height, but theirs came with the suggestion to apply as.hclust() first. I converted the agnes object to an hclust and passed that directly into cutree. That seemed to solve the problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.