treedata.table (version 0.1.0)

as.treedata.table: Combine tree (or set of trees) and data.frame into a single treedata.table object

Description

This function takes as input a tree of class phylo or multiPhylo and a data.frame and combines them into a treedata.table. If a multiPhylo is provided, all trees must have the same tip.labels. treedata.table object is sorted such that the rows in the data.table are matched to the tip.labels of the phylogeny. Tip.labels on the tree must match a column of tip names in the input data.frame. The output of this function will be a treedata.table, which can be manipulated as a data.table.

Usage

as.treedata.table(tree, data, name_column = "detect")

Arguments

tree

A tree of class phylo or multiple trees of class multiPhylo

data

A dataset in format data.frame

name_column

A character indicating the name of taxa in data.frame. If set to detect (default) as treedata.table will auto-detect this column

Value

An object of type treedata.table containing the tree and data.table

Examples

Run this code
# NOT RUN {
data(anolis)
anolis2 <- anolis$phy
anolis2$tip.label[1] <- "NAA"
anolis1 <- anolis$phy
anolis1$tip.label[1] <- "NAA"
trees <- list(anolis1, anolis2)
class(trees) <- "multiPhylo"
treesFM <- list(anolis$phy, anolis$phy)
class(treesFM) <- "multiPhylo"

# A phylo object that fully matches the data
td <- as.treedata.table(tree = anolis$phy, data = anolis$dat)
# A multiphylo object that fully matches the data
td <- as.treedata.table(tree = treesFM, data = anolis$dat)
# A phylo object that partially matches the data
td <- as.treedata.table(tree = anolis1, data = anolis$dat)
# A multiphylo object that partially matches the data
td <- as.treedata.table(tree = trees, data = anolis$dat)
# }

Run the code above in your browser using DataCamp Workspace