Re: [R] problem accessing trees after read.nexus from ape package

From: Ben Bolker <bolker_at_ufl.edu>
Date: Wed 10 May 2006 - 03:23:42 EST

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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed May 10 03:27:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 10 May 2006 - 04:09:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.