This should be relatively simple but for some reason, I’m coming up stumped.
I want to reorder a phylogenetic distance matrix so that the columns are in alphabetical order.
Here is a quick example:
require("ape")
set.seed(5)
dist(cophenetic(rtree(5)))
Any ideas?
if
T <- dist(cophenetic(rtree(5)))T is of class
distso it doesnt have names, just labels.You can order its labels
You can coerce it into a matrix, and then sort it
Then as @Roland suggested, convert it back to
distIf you would like to control the format of the matrix, you can use the following