[R] problem accessing trees after read.nexus from ape package
Ben Bolker
bolker at ufl.edu
Tue May 9 19:23:42 CEST 2006
Betty Gilbert <lgilbert <at> berkeley.edu> writes:
>
> Hello,
> I've been trying to figure out how to access the individual elements
> from an object of class phylo.
> I am reading in 201 trees created by paup as below.
>
> > read.nexus("A_30knj_200t.txt", tree.names= NULL) -> anj30
[snip]
>
> x<- anj30[1]
> > class(x)
> [1] "list"
>
> > as.phylo(x)
> Error in as.phylo(x) : no applicable method for "as.phylo"
> > cophenetic.phylo(x)
> Error in cophenetic.phylo(x) : your tree has no branch lengths defined
>
> and
> > cophenetic.phylo(anj30[1])
> Error in cophenetic.phylo(anj30[1]) : your tree has no branch lengths defined
>
(1) using [[ instead of [ will help; [ returns a LIST (possibly just
a one-element list), while [[ returns an ELEMENT of the list.
e.g.:
> x <- list("a","b","c")
> x[1]
[[1]]
[1] "a"
> class(x[1])
[1] "list"
> x[[1]]
[1] "a"
> class(x[[1]])
[1] "character"
(2) cophy <- lapply(anj30,cophenetic.phylo) should process all
of your phylogenies and return the answer as a list of cophylogenies.
good luck,
Ben Bolker
More information about the R-help
mailing list