This is a test version of Biostars. For the public version, visit https://www.biostars.org.
prunning posterior distribution of trees in R

I have a posterior distribution of trees from a Bayesian analysis in nexus format. Is there a function in R to prune these trees to match my trait dataset? Something like the treedata function in the R package geiger seems to do what I want, but it does not handle multiple trees.

r phylogeny

1 answer

keep.tip from ape and lapply should do the job:

library(ape)  
trees <- .uncompressTipLabel(trees)
trees <- lapply(trees, keep.tip, trait_names)
trees
class(trees) <- "multiPhylo"
trees <- .compressTipLabel(trees)

Here trees is a multiPhylo object (you can read them in with read.nexus) and trait_names is a vector with the tip labels you want to keep.

Log in to answer this question.