Hi Alisha,
You can use "order" rather than "sort" to get numbers, which you can
then use to reorder the matrix. Such as:
library(ape)
data(bird.orders)
tr<-bird.orders
C1<-cophenetic(tr)
o<-order(rownames(C1))
C2<-C1[o,o]
C2 is now the matrix with rows and columns in alphabetical order.
Hope this is helpful,
Luke Harmon
Department of Biological Sciences
University of Idaho
[EMAIL PROTECTED]
On Nov 1, 2008, at 10:42 PM, Alisha Rossi wrote:
> Is there a way to produce a cophenetic matrix with the rows and
> columns in
> alphabetical order? I would like to compare phylogenetic trees by
> comparing
> the cophenetic matrix of each tree (all same taxa). However, the
> cophenetic
> matrices do not usually have the same ordering if the topology of
> the trees
> are different. If there isn't a direct method to produced alphabetized
> cophenetic matrices, I have created the following code that works
> but has a
> problem.
>
>
>
> C1<-cophenetic(tr)
>
> C1Asc<- C1 [c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
> "L",
> "M", "N", "O", "P"),] # sorts rows by row names
>
> C1<-C1Asc[,c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
> "L",
> "M", "N", "O", "P")] # sorts columns by column names
>
>
>
> The problem with this code is that it requires that I type in every
> row and
> column name separated by commas. There exists a command
> sort(rownames(C2))
> that yields the correct ordering but does not include the necessary
> commas
> in between, thus I will not be able to use my R code when comparing
> trees
> with hundreds of taxa. I've unsuccessfully tried creating a "for
> loop" to
> insert commas. Is there another way to insert a comma between each
> element
> in the list? Also, I am using data in "Newick" format, and the
> cophenetic
> matrices always have one non-zero element in the diagonal. I'm not
> sure if
> all the other values in the matrix are correct but this is an
> obvious error.
>
>
>
> Thank you,
>
> Alisha
>
>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-phylo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
[[alternative HTML version deleted]]
_______________________________________________
R-sig-phylo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo