FES 720 Introduction to R

LAB: *apply

This is the lab associated with the lecture and lesson on *apply in R.

Please upload your final completed lab on the Assignments page in Canvas, as per the instructions below.

You are welcome and expected to ask for help from the instructors if you get stuck: Please also come to the R Bootcamp on Friday—there is coffee and snacks!

A. Michigan Tree Plot data

# Read in the data
dat_tree <- read.table("http://www.simonqueenborough.info/R/data/treespecies_cleandata.txt", 
                       header = TRUE, sep = '\t')

Using functions from the *apply family:

  1. What is the mean DBH of each species?

  2. What is the median DBH of dead and alive trees?

  3. What is the maximum DBH of each species?

  4. What is the minimum DBH of each species?

  5. What is the standard deviation of DBH of each species?

  6. What is the sum of the DBH of tree of each species that are alive and dead (Check the help page if you cannot work out how to split a dataframe by two categorical columns).

  7. How many trees of each species are present? Do not use table().

B. Michigan Tree Plot data II

First, modify the tree data using the split() function.

new_tree <- split(dat_tree, dat_tree$species) 

Using new_tree, answer the following:

  1. What kind of object is new_tree?

  2. How many trees of each species are present? Return this answer as a list and a vector.

C. New Haven Road Race 5K data

# Read in NHV road race results 2015.
dat.nhv <- read.table("http://www.simonqueenborough.info/R/data/race-data-full.txt", sep = '\t', header = TRUE)
  1. What is the slowest Pace ($Pace_mins) for each City?

  2. What was the fastest Pace for each age group?

  3. What was the mean Pace for each sex and age class combination?

How to write up your answers

Please check the help page for a reminder, if you need to.

Updated: 2017-10-11