This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Drop tip from multiPhylo object in R

I have 100s of phylogenetic trees in a multiPhylo object. There is one tip I need to drop from all of these trees. How can I do this in R?

r phylogeny

Provide an example input data. Make a dummy multiPhylo object with 2 or 3 trees, and post output of dput(myDummyTrees).

1 answer

A multiPhylo object is basically just a list of phylo objects. These can be operated on using the standard approaches for working with lists, so we use lapply to return a list for coercion back to the starting data type.

library(ape)
one <- rlineage(1, 1)
two <- rlineage(1, 1)
combined <- c(one, two)
# check: returns "multiPhylo"
class(combined)
results <- lapply(combined, drop.tip, "t2")
# explicitly convert back to an object of class multiPhylo
final <- do.call(c, results)

Log in to answer this question.