[R] Clustering within part of a cluster result

Albert Vernon Smith avsmith at gmail.com
Fri Jul 10 03:02:13 CEST 2009


How can I cluster and order within part of a previous clustering result?

For example, I am clustering and ordering results as follows:

> rows <- 30
> cols <- 3
> x <- matrix(sample(-1:1,rows*cols,replace=T), nrow=rows, ncol=cols,dimnames=list(c(paste("R",1:rows,sep="")),c(paste("C",1:cols,sep=""))))
> x
    C1 C2 C3
R1   0  1  1
R2   0 -1  1
R3  -1  1  0
R4  -1  0  1
R5   0 -1  0
R6  -1 -1  1
R7  -1 -1 -1
R8  -1 -1  0
...
> hc <- hclust(dist(x, method = "binary"),method="single")
> hc <- as.dendrogram(hc)
> ord.hc <- order.dendrogram(hc)
> xc <- x[rev(ord.hc),]
> xc
    C1 C2 C3
R7  -1 -1 -1
R6  -1 -1  1
R9   1 -1  1
R11  1  1 -1
R12 -1 -1 -1
R16 -1 -1  1
R18 -1 -1 -1
R24  1 -1 -1
R27 -1 -1  1
R2   0 -1  1
R1   0  1  1
R10  0 -1 -1
...
>

Given the binary distance I am using, the first nine rows all have a
distance of 0 to one another.  How can I sort again within certain
nodes to bring those which are closer together.  In the example above,
I'd like some sort of cluster within the first 9 rows so that "R7",
"R12", and "R18" are together, as they are all -1,-1,-1, and
R6/R16/R27, etc.

How might I go about that?

Thanks,
-albert




More information about the R-help mailing list