# 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
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.
``````
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?