Hello List, I am trying to implement a hierarchical cluster using the hclust method agglomerative single linkage method with a small wrinkle. I would like to cluster a set of numbers on a number line only if they are within a distance of 500. I would then like to print out the members of this list. So far I can put a vector:> x<-c(2,10,200,300,600,700)into a distance matrix:> dist(x,method="manhattan")1 2 3 4 5 2 8 3 198 190 4 298 290 100 5 598 590 400 300 6 698 690 500 400 100 I can then cluster these distances using:>hc<-hclust(v, method = "complete")Next, I "believe" I set my distance limit in the cluster using the command>cutree(hc, h=500)1 1 1 1 2 2 1 3 [1] 1 1 1 1 2 2 This seems to produce the correct result however, whatt I am unable to do is go back and extract and print out the members of each cluster. Any herp would be greatly appreciated. Thanks [[alternative HTML version deleted]]
On Wed, May 11, 2011 at 10:12 AM, rna seq <rna.seeker at gmail.com> wrote:> Hello List, > > I am trying to implement a hierarchical cluster using the hclust method > agglomerative single linkage method with a small wrinkle. I would like to > cluster a set of numbers on a number line only if they are within a distance > of 500. I would then like to print out the members of this list. > > So far I can put a vector: >> x<-c(2,10,200,300,600,700) > into a distance matrix: >> dist(x,method="manhattan") > ? ?1 ? 2 ? 3 ? 4 ? 5 > 2 ? 8 > 3 198 190 > 4 298 290 100 > 5 598 590 400 300 > 6 698 690 500 400 100 > > I can then cluster these distances using: >>hc<-hclust(v, method = "complete") > > Next, I "believe" I set my distance limit in the cluster using the command > >>cutree(hc, h=500) > 1 1 1 1 2 2 1 3 > [1] 1 1 1 1 2 2 > > This seems to produce the correct result however, whatt I am unable to do is > go back and extract and print out the members of each cluster. Any herp > would be greatly appreciated.Very simple. labels = cutree(hc, h=500) # members of cluster 1: x[labels==1] # members of cluster 2: x[labels==2] HTH, Peter
You can print out the nodes and their corresponding clusters into a file by this:> write.table (hc,file="hc_40clusters.cvs", quote=FALSE, sep=" ")-- View this message in context: http://r.789695.n4.nabble.com/hierarchical-clustering-within-a-size-limit-tp3515354p4080551.html Sent from the R help mailing list archive at Nabble.com.