[R] Making as.hclust.phylo for non binary trees work?

Tal Galili tal.galili at gmail.com
Thu Oct 1 15:25:08 CEST 2015


Dear R-help mailing list (and Emmanuel, the ape package maintainer),

I would like to change a non binary phylo object to hclust, but this does
not seem to work smoothly.

Here is a small R code to demonstrate the problem:

# an hclust tree with 3 branches from the root
hc <- hclust(dist(c(1:2, 4,5, 7,8)), method = "single")
plot(hc)

# we can change it to phylo just fine:
library(ape)
phy <- as.phylo(hc)
plot(phy)
# for some reason it claims the object is binary
is.binary.tree(phy) # TRUE

# it turns to hclust
hc2 <- as.hclust(phy)
# but the plotting fails:
plot(hc2)
# Error in plot.hclust(hc2) : 'merge' matrix has invalid contents
cutree(hc2, 2) # works, but doesn't give any warning that it actually can't
provide with only 2 clusters...



Thanks upfront for any help.

Best,
Tal



----------------Contact
Details:-------------------------------------------------------
Contact me: Tal.Galili at gmail.com |
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------

	[[alternative HTML version deleted]]



More information about the R-help mailing list