Hi Elaine.
A simpler way to do method 1 that doesn't require na.omit or match is:
# if there are species in the tree that are missing from the data:
ss<-species.to.keep[,1] # species in the data
tree<-birdtree
tree.pruned<-drop.tip(tree,setdiff(tree$tip.label,ss))
I would guess that method 2 isn't working because your species names are
not row names in your data matrix. To have that, you could do:
birddata<-read.csv("H:/birddata_family_20130405.csv",header=T,row.names=1)
All the best, Liam
Liam J. Revell, Assistant Professor of Biology
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
email: liam.rev...@umb.edu
blog: http://blog.phytools.org
On 4/5/2013 8:54 AM, Elaine Kuo wrote:
Hello
This Elaine.
I tried to prune a phylogeny tree using two methods based on the code
attached.
Method 1 returned the tip.label sharing between birddata and birdtree.
Method 2 returned nothing.
Please kindly indicate why Method 2 failed to prune the tree.
Also, please kindly explain the command “birdtree$tip.label[-na.omit”
Thank you again.
Code
Method 1
Library(ape)
birddata <- read.csv("H:/ birddata_family_20130405.csv", header = TRUE)
birdtree <- read.nexus("H:/ birddata_family_20130405.nexus")
setwd("H:)
## prune the phylogeny to include only species which are in the data set
species.to.keep<-read.csv("H:/ birddata_family_20130405.csv", header = TRUE)
birdtree.pruned<-drop.tip(birdtree,birdtree$tip.label[-na.omit(match(species.to.keep[,1],birdtree$tip.label))])
Method 2
Library(ape)
birddata <- read.csv("H:/ birddata_family_20130405.csv", header = TRUE)
birdtree <- read.nexus("H:/ birddata_family_20130405.nexus")
setwd("H:)
## prune the phylogeny to include only species which are in the data set
temp <- name.check(birdtree, birddata)
birdtree.pruned <- drop.tip(birdtree, tip=temp$Tree.not.data)
[[alternative HTML version deleted]]
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/
_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/