Remember to

  • download surveys.csv.
  • download species.csv.
  • Consider removing the dplyr package so you can demonstrate installing it.

Packages

Basic dplyr

  • Start a new project (modeling good practice)
surveys <- read.csv("surveys.csv")

Do Exercise 2 - Shrub Volume Data Basics.

Aggregation

surveys_by_species <- group_by(surveys, species_id)

Do Exercise 3 - Shrub Volume Aggregation.

Joins

species <- read.csv("species.csv")
combined <- inner_join(surveys, species, by = "species_id")
head(combined)

Do Exercise 4 - Shrub Volume Join.

Pipes

surveys_DS <- filter(surveys, species_id == "DS")
surveys_DS_by_yr <- group_by(surveys_DS, year)
avg_weight_DS_by_yr <- summarize(surveys_DS_by_yr, avg_weight = mean(weight, na.rm=TRUE))
surveys %>%
  filter(species_id == "DS") %>%
  group_by(year) %>%
  summarize(avg_weight = mean(weight, na.rm=TRUE))

Do Exercise 5 - Fix the Code.