Learn R Programming

Claddis (version 0.7.0)

find_mrca: Find ancestor

Description

Finds the last common ancestor (node) of a set of two or more descendant tips.

Usage

find_mrca(descendant_names, tree)

Value

ancestor_node

The ancestral node number.

Arguments

descendant_names

A vector of mode character representing the tip names for which an ancestor is sought.

tree

The tree as a phylo object.

Author

Graeme T. Lloyd graemetlloyd@gmail.com

Details

Intended for use as an internal function for trim_matrix, but potentially of more general use.

Examples

Run this code

# Create a simple four-taxon tree:
tree <- ape::read.tree(text = "(A,(B,(C,D)));")

# Plot the tree:
ape::plot.phylo(tree)

# Add nodelabels and show that the most recent common
# ancestor of B, C, and D is node 6:
ape::nodelabels()

# Use find_mrca to show that the most recent common
# ancestor of B, C, and D is node 6:
find_mrca(
  descendant_names = c("B", "C", "D"),
  tree = tree
)

Run the code above in your browser using DataLab