# Cluster with distance threshold in R

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?

• @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? Jul 28 '14 at 18:57
• 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. Jul 28 '14 at 23:44

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)

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