---
title: "Wrangling 1<br>Case Study: Detroit Tigers"
author: "Keith VanderLinden<br>Calvin University"
output:
  xaringan::moon_reader:
    nature:
      titleSlideClass: ["left", "top"]
      highlightLines: true
      ratio: "16:9"     
---

```{r child = "../../../web/resources/scripts/slide-setup.Rmd"}
```

```{r packages, echo = FALSE, warning = FALSE, message = FALSE}
options(dplyr.print_max = 12)
```

# The Dataset: Lahman Baseball Database

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

```{r}
Teams
```

???
[Baseball Example 1](https://mdsr-book.github.io/mdsr2e/ch-dataI.html#sec:mets)

fill in the details...

continued next unit...

---
# Performance of the Detroit Tigers

How well did the Detroit Tigers do in the 2000s?

.pull-left[
```{r baseball-1, results = "hide", message = FALSE, warning = FALSE}
tigers_2000 <- Teams %>% 
  select(yearID, teamID, W, L, R, RA) %>%
  filter(teamID == "DET" & 
           yearID %in% 2000:2019) %>%
  rename(RS = R) %>%
  mutate(wpct = W / (W + L)) %>%
  mutate(wpct_hat = 1 / (1 + (RA/RS)^2)) %>%
  mutate(w_hat = wpct_hat * (W + L)) %>%
  mutate(diff = W - w_hat) %>%
  arrange(desc(diff))

tigers_2000
```
]
.pull-right[
```{r ref.label = "baseball-1", echo = FALSE, warning = FALSE, output.lines = 12}
```
]

???
Graph this.

Cf. https://en.wikipedia.org/wiki/Detroit_Tigers
