5.2 An alternative practice data set
# Import the file
species <- read.csv(file.path(DATADIR, "species.csv"), header = TRUE,
as.is = c("Scientific_name","Common_name", "Taxon_author"))
# Identify the classes of organism
levels(species$Class)
## [1] "" " " "amphibians"
## [4] "arachnids" "birds" "bivalves"
## [7] "blue-green algae" "branchiopods" "brown algae"
## [10] "cartilaginous fishes" "club fungi" "club mosses"
## [13] "conifers" "cycads" "diatoms"
## [16] "dinoflagellates" "euglenoids" "ferns"
## [19] "golden-brown algae" "green algae" "higher dicots"
## [22] "hornworts" "insects" "lampreys"
## [25] "liverworts" "lobe-finned fishes" "lower dicots"
## [28] "malacostracans" "mammals" "maxillopods"
## [31] "monocots" "mosses" "quillworts"
## [34] "ray-finned fishes" "red algae" "reptiles"
## [37] "sac fungi" "slime molds" "snails"
## [40] "spike mosses" "uncertain" "whisk ferns"
## [43] "yellow-green algae"
# OR
unique(species$Class)
## [1] amphibians arachnids
## [4] birds bivalves branchiopods
## [7] cartilaginous fishes insects lampreys
## [10] lobe-finned fishes malacostracans mammals
## [13] maxillopods ray-finned fishes reptiles
## [16] snails club fungi sac fungi
## [19] uncertain slime molds
## [22] higher dicots liverworts ferns
## [25] monocots mosses lower dicots
## [28] hornworts conifers cycads
## [31] quillworts club mosses whisk ferns
## [34] spike mosses red algae green algae
## [37] diatoms blue-green algae brown algae
## [40] yellow-green algae golden-brown algae euglenoids
## [43] dinoflagellates
## 43 Levels: amphibians arachnids birds bivalves ... yellow-green algae
# Select just the entries for a single class
species.class <- species[(species[,"Class"] == "amphibians"),]
# Remove the unwanted fields
species.class <- subset(species.class,
select = -c(Taxon_Id, Kingdom, Class, EPBC_status))
# Then to finish things off cleanly, export the data
write.csv(species.class, file = "Queensland_amphibians.csv", row.names = FALSE)