changing species names in phylogeny in R
1
0
Entering edit mode
5.2 years ago
phylofun ▴ 50

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.

phylogenetics R • 3.5k views
ADD COMMENT
0
Entering edit mode

Without an example it is impossible to reproduce the problem.

ADD REPLY
0
Entering edit mode
5.2 years ago
Brice Sarver ★ 3.8k

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.

ADD COMMENT

Login before adding your answer.

Traffic: 1493 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6