Using taxize to get a classification
Install taxize
install.packages("taxize")
Load taxize
library(taxize)
Get a set of species names
sp <- names_list("species", 10)
Get classifications for each species
res <- classification(sp, db = "col")
Remove missing taxa
res <- res[!is.na(res)]
Combine results to a data.frame, and select only certain ranks
library(plyr)
ldply(res, function(x) x[x$rank %in% c('Kingdom','Family','Genus'),])
Or this way
library(plyr)
library(reshape2)
ldply(res, function(x){
tmp <- data.frame(t(x$name))
names(tmp) <- x$rank
tmp
})
.id Kingdom Phylum Class Order Family Genus
1 Pohlia camptotrachela Plantae Bryophyta Bryopsida Bryales Bryaceae Pohlia
2 Spiridens vieillardii Plantae Bryophyta Bryopsida Bryales Spiridentaceae Spiridens
3 Gunnera katherine-wilsoniae Plantae Tracheophyta Magnoliopsida Gunnerales Gunneraceae Gunnera
4 Encalypta vulgaris Plantae Bryophyta Bryopsida Pottiales Encalyptaceae Encalypta
5 Hampeella pallens Plantae Bryophyta Bryopsida Isobryales Ptychomniaceae Hampeella
write.csv(df, file="awafsdsdf.csv", row.names=FALSE)