changing species names in phylogeny in R
I have a column of species in the order in which they appear in my phylogeny (output from $tip.labels). I want to swap out this list of species with a new species list such that is in the same order as my original species list and replaces all the species in $tip.labels from an R phylo object.
• 4,481 views
•
link
1 answer
You don't really have a question above, you haven't provided an example, etc. Perhaps starting here will help? That said, I'm going to guess that you want to rename labels on a phylo object based on another character vector of equal length. This is straightforward.
library(ape)
rename_labels <- function(tree, vec) {
tree$tip.label <- vec
return(tree)
}
a <- read.tree("your_tree.tre")
b <- c("your", "vector", "of", "species")
renamed_tree <- rename_labels(tree = a, vec = b)
You obviously don't need the function if you're just doing this as a one-off.
• 0 views
•
link
Log in to answer this question.
Without an example it is impossible to reproduce the problem.