---
title: "midterm"
author: "Karl Rohe"
output: html_document
---
  
## Midterm.
  
#### 1.  Map the delay by destination.
  
  Compute the average delay by destination, then join on the airports data frame so you can show the spatial distribution of delays. Here’s an easy way to draw a map of the United States.  You are welcome to use this code or some other code. 

```{r} 
library(tidyverse)
library(nycflights13)

airports %>%
  semi_join(flights, c("faa" = "dest")) %>%
  ggplot(aes(lon, lat)) +
  borders("state") +
  geom_point() +
  coord_quickmap()
```

You might want to use the size or colour of the points to display the average delay for each airport.

```{r}

flights
planes
airlines
airports
weather

# put your answer here.
```


#### 2.   Do planes trade ownership?

You might expect that there’s an implicit relationship between plane and airline, because each plane is flown by a single airline. Explore this conjecture using data. (Let's assume that the tail number of a plane does not change.)

```{r}
# put your answer here. 
```


#### 3a.  Plane's average speed.

Notice that ```flights$air_time``` is in minutes.  Make a new column that is the air time in hours. 

```{r}
# put your answer here.  
```


#### 4b. Average speed

For each flight, compute the average speed of that flight (in miles per hour).  Then, for each plane, compute the average of those average speeds. Display it in a histogram. You can use a base R histogram ```hist``` or ggplot's ```geom_histogram```. 

```{r}
# put your answer here.  
```




#### 5. Bonus

Make a table where each row is a destination, each column is a carrier, and each element is the number of times that the carrier has flown to that destination.  Ensure that you only count flights that arrived at the destination. 

```{r}
# put answer here
```

