0
$\begingroup$

I'd like to get clusters with a maximum inner distance threshold.

Now I use hc <- hclust(d) and cutree(hc, numofclasses).

But I would like to use something like in python:

>>> cl = HierarchicalClustering(data, lambda x,y: abs(x-y))
>>> cl.getlevel(10)     # get clusters of items closer than 10

How can I get this in R?

$\endgroup$
2
  • $\begingroup$ @Anony-Mousse, I can sympathize with your sentiment, but perhaps you could have expressed it slightly less abusively. Did you notice that carlos has only 3 reputation points? Could that mean that he is new to the community? That he hasn't yet had time to fully appreciate the social mores of this community? (e.g., RTFM) Did you respond to him like a surly curmudgeon? Does that make him feel welcome in the community? Could you have just as easily said, "Carlos, please read the documentation before posting?" Or perhaps something like waldir-leoncio 's comment on the accepted answer? $\endgroup$ Jul 28 '14 at 18:57
  • $\begingroup$ Reading the documentation is a universal rule (google RTFM, for the original meaning; it was not polite either), and not specific to StackExchange... yet, people constantly fail at doing so; apparently because everybody is too polite to tell them to RTFM. $\endgroup$ Jul 28 '14 at 23:44
5
$\begingroup$

You can use the h argument in cutree(). It will split the elements in clusters based on the "height" of the dendrogram. I will sketch the code, because you do not provide data.

hc <- hclust(data)
plot(hc); text(hc)       ## see the output
hc2 <- cutree(hc, h=10)

The height of the dendrogram corresponds to the distance between two nodes, but the relationship may not be 1-to-1 with your python implementation.

$\endgroup$
1
  • $\begingroup$ @carlos, You can learn a lot about a function by running ?cutree. ;) $\endgroup$ Apr 18 '14 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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