Skip to contents

Prune a tree or a collection of trees and keep only requested tips.

Usage

keep_tips(x, tips)

# S3 method for phylo
keep_tips(x, tips)

# S3 method for multiPhylo
keep_tips(x, tips)

# S3 method for rankedPhylo
keep_tips(x, tips)

Arguments

x

a tree of class "phylo" or "multiPhylo"

tips

tip labels to keep

Value

a pruned tree or a collection

Examples

tree = rankedPhylo(5)
# select randomly 3 tips to keep
tips = sample(tips(tree), 3)
keep_tips(tree, tips)
#> 
#> Phylogenetic tree with 3 tips and 2 internal nodes.
#> 
#> Tip labels:
#>   t1, t4, t5
#> 
#> Rooted; includes branch lengths.

trees = rankedPhylo(3:7)
# get tips from the first tree
tips = tips(trees[[1]])
# prune all trees, all of them will have 3 tips
keep_tips(trees, tips)
#> 5 phylogenetic trees