[R] cut.dendrogram and cutree

Agustin Lobo Agustin.Lobo at ija.csic.es
Mon Oct 29 08:57:28 CET 2007


Yes, I was just trying unlist() in a similar way. All I need is
to apply labels() and/or unlist() to each element of the list
dend2$lower:

lista <- vector("list", length(dend2$lower))
for (i in 1:length(dend2$lower)) {
	lista[[i]] <- labels(dend2$lower[[i]])
	}
lista

Thanks!

Agus

Yaomin Xu escribió:
> Agus,
> How about the following?
> 
>> labels(dend2$lower[[1]])
> [1] "Florida"        "North Carolina"
>> labels(dend2$lower[[2]])
>  [1] "California"     "Maryland"       "Arizona"        "New Mexico"
>   "Delaware"       "Alabama"        "Louisiana"
>  [8] "Illinois"       "New York"       "Michigan"       "Nevada"
>   "Alaska"         "Mississippi"    "South Carolina"
>> labels(dend2$lower[[3]])
>  [1] "Washington"    "Oregon"        "Wyoming"       "Oklahoma"
> "Virginia"      "Rhode Island"  "Massachusetts" "New Jersey"
>  [9] "Missouri"      "Arkansas"      "Tennessee"     "Georgia"
> "Colorado"      "Texas"
>> labels(dend2$lower[[4]])
>  [1] "Idaho"         "Nebraska"      "Kentucky"      "Montana"
> "Ohio"          "Utah"          "Indiana"       "Kansas"
>  [9] "Connecticut"   "Pennsylvania"  "Hawaii"        "West Virginia"
> "Maine"         "South Dakota"  "North Dakota"  "Vermont"
> [17] "Minnesota"     "Wisconsin"     "Iowa"          "New Hampshire"
> 
> Yaomin
> 
> On 10/29/07, Agustin Lobo <Agustin.Lobo at ija.csic.es> wrote:
>> Thanks,
>>
>> But this is not solving my problem, let me further explain by following
>> the example in the help page for dendrogram:
>>
>> require(graphics); require(utils)
>> hc <- hclust(dist(USArrests), "ave")
>> dend1 <- as.dendrogram(hc)
>> dend2 <- cut(dend1, h=70)
>> plot(dend2$upper,center=T)
>>
>> What I want to know are the original elements in each of the final
>> branches of dend2$upper (the ones labeled "Branch 1", "Branch 2" etc)
>> (or the branch for each of the original elements).
>>
>> May be I could with dend2$lower, but can't find the way.
>>
>> Agus
>>
>> Yaomin Xu escribió:
>>> Sorry, forget to put your email address.
>>>
>>> ---------- Forwarded message ----------
>>> From: Yaomin Xu <yaomin at case.edu>
>>> Date: Oct 28, 2007 5:14 PM
>>> Subject: Re: [R] cut.dendrogram and cutree
>>> To: r-help at r-project.org
>>>
>>>
>>> Agus,
>>>
>>> we use cut.tree when it makes sense to use a specific h as a global
>>> criterion to split the tree.
>>>
>>> In your case, you might want to access the tree using '[['. Examples
>>> below borrow the samples you provided in your code:
>>>
>>> 1) There are two branches in your dend1. To get the left branch, you can do
>>>
>>>> dend1.1 <- dend1[[1]]
>>>> labels(dend1.1)
>>> where labels function gives you all the states you have under that branch.
>>>
>>> 2) There are two big sub-branches on the right branch of brand1, to
>>> access the right one of those two sub-branches, you can do,
>>>
>>> dend1.2.2 <- dend1[[c(2,2)]]  # or dend1.2.2<- dend1[[2]][[2]]
>>> lables(dend1.2.2)  ## will list you all the members.
>>>
>>> So the branches of a dendrogram object can be accessed in a binary
>>> tree fashion, use '1' for the tree on the left and '2' for the tree on
>>> the right.
>>>
>>> hope the above helps.
>>>
>>> yaomin
>>>
>>> ------
>>> Yaomin Xu
>>> Statstical Computing and Bioinformatics
>>> The Cleveland Clinic Foundation
>>>
>>>
>> --
>> Dr. Agustin Lobo
>> Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>> LLuis Sole Sabaris s/n
>> 08028 Barcelona
>> Spain
>> Tel. 34 934095410
>> Fax. 34 934110012
>> email: Agustin.Lobo at ija.csic.es
>> http://www.ija.csic.es/gt/obster
>>
> 
> 

-- 
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster



More information about the R-help mailing list