I want to give a species a new name in my tree of class phylo
(using the ape
package).
I tried:
tree$tip.label["speciesX"] <- "speciesY"
This did not do what I wanted. Any suggestions?
I want to give a species a new name in my tree of class phylo
(using the ape
package).
I tried:
tree$tip.label["speciesX"] <- "speciesY"
This did not do what I wanted. Any suggestions?
The problem is that you can't index the tip labels the way you want (you want to replace the tip label whose value is "speciesX", not the one whose name is "speciesX"; the tip label vector doesn't have names). Silly as it sounds, you need something like
tree$tip.label[tree$tip.label=="speciesX"]
to identify the right value to replace.Example:
Rename:
You could write a function to do this, something like (not tested!)