Skip to content

Instantly share code, notes, and snippets.

@dfalster
Created January 3, 2014 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfalster/8232865 to your computer and use it in GitHub Desktop.
Save dfalster/8232865 to your computer and use it in GitHub Desktop.
Function to convert vector of binomial species names into a vector of 6 letter abbreviations, taking first 3 letters from first and second names. Example: spp_code(c("Quassia baileyana","Rhodomyrtus trineura","Rockinghamia angustifolia"))
spp_code <- function(species_names){
sapply(strsplit(species_names, " "), function(x) tolower(paste0(substr(x[1], 1,3), substr(x[2], 1,3))))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment