Reputation: 29
I'd like to run the same function across multiple phylogenies that are stored as a multiPhylo object.
For example, lets say I have multiPhylo of 1,000 trees, and I want to sum the edge/branch lengths in each of these trees. I know for a single tree I can just use:
sum(tree$edge.length)
But I can't work out how to do this for all the trees in a multiPhylo. I'm sure this is simple, but it's beyond me. Can anyone help?
Thanks
Dan
Upvotes: 1
Views: 842
Reputation: 2250
Class multiPhylo
is a list (str(tree)
) and thus provides functionality that R
uses to handle lists. To sum edge lengths of individual trees, use the lapply
function.
lapply(tree, FUN = function(x) sum(x$edge.length))
Upvotes: 4