[R] hclust and plot functions work, cutree does not

Sarah Goslee sarah.goslee at gmail.com
Thu Mar 29 15:34:34 CEST 2012


What does "does not work" mean? Do you get an error message? Or a
warning? Or a result, but one that isn't what you expected?

Did you look at the results of the example in ?cutree to make sure
what the function does is what you think it should do?

>      hc <- hclust(dist(USArrests))
>      cutree(hc, k=1:5) #k = 1 is trivial
               1 2 3 4 5
Alabama        1 1 1 1 1
Alaska         1 1 1 1 1
Arizona        1 1 1 1 1
Arkansas       1 2 2 2 2
California     1 1 1 1 1

As always, a clear statement of your problem and a reproducible
example are required.

Sarah

On Thu, Mar 29, 2012 at 6:28 AM, Vinod Hegde <vinod.hegde.c at gmail.com> wrote:
> Hi,
>
> I have the distance matrix computed and I feed it to hclust function. The
> plot function produces a dense dendrogram as well. But, the cutree function
> applied does not produce the desired list.
> Here is the code
>
>        x=data.frame(similarity_matrix)
> colnames(x) = c(source_tags_vec)
> rownames(x) = c(source_tags_vec)
> clust_tree=hclust(as.dist(x),method="complete")
> plot(clust_tree)
> cutree(clust_tree,k=1:5)
>
> Similarity matrix is a symmetric matrix.
> I really thank for any input on this.
>



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list