Created
December 14, 2015 21:05
-
-
Save ateucher/34994dc6cdbae8776336 to your computer and use it in GitHub Desktop.
Sort a list of bird species taxonomically using the rebird packaage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Make some mock data for demonstration purposes: | |
| Species <- c("Green-winged Teal", "Bald Eagle", "Swainson's Hawk", "Red-tailed Hawk", | |
| "American Coot", "Rock Pigeon", "Red-naped Sapsucker", "Northern Flicker", | |
| "American Kestrel", "Western Wood-Pewee", "Willow Flycatcher", | |
| "Dusky Flycatcher", "Say's Phoebe", "Eastern Kingbird", "Black-billed Magpie", | |
| "Common Raven", "Tree Swallow", "Cliff Swallow", "House Wren", | |
| "Marsh Wren", "Mountain Bluebird", "American Robin", "European Starling", | |
| "Cedar Waxwing", "Yellow-rumped Warbler", "Clay-colored Sparrow", | |
| "White-crowned Sparrow", "Vesper Sparrow", "Western Meadowlark", | |
| "Yellow-headed Blackbird", "Brewer's Blackbird", "Mallard", "Blue-winged Teal", | |
| "Lesser Scaup", "Ruffed Grouse", "Wilson's Snipe", "Black-chinned Hummingbird", | |
| "Downy Woodpecker", "Warbling Vireo", "Northern Rough-winged Swallow", | |
| "Barn Swallow", "Black-capped Chickadee", "Mountain Chickadee", | |
| "Orange-crowned Warbler", "Yellow Warbler", "Chipping Sparrow", | |
| "Savannah Sparrow", "Song Sparrow", "Western Tanager", "Red-winged Blackbird", | |
| "Bullock's Oriole", "Pine Siskin") | |
| N_obs <- rpois(length(Species), 2) | |
| bird_list <- data.frame(Species, N_obs, stringsAsFactors = FALSE) | |
| library(rebird) | |
| library(dplyr) | |
| ## Get global taxonomy table which contains taxon order | |
| tax <- ebirdtaxonomy() | |
| ## Join the bird list data frame with the taxonomy data frame | |
| bird_list <- left_join(bird_list, tax, by = c("Species" = "comName")) | |
| ## Sort by taxonOrder | |
| bird_list_sorted <- arrange(bird_list, taxonOrder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment