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

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

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

# Finding Miguel Cabrera in the Baseball Database

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

```{r}
cabrera_batting <- Batting %>%
  inner_join(People, by = "playerID") %>%
  filter(nameFirst == "Miguel" & nameLast == "Cabrera")
cabrera_batting
```
???
[Baseball Example 1](https://mdsr-book.github.io/mdsr2e/ch-dataI.html#sec:mets)
[Baseball Example 2](https://mdsr-book.github.io/mdsr2e/ch-join.html#extended-example-manny-ramirez)

# Performance of Miguel Cabrera

```{r}
cabrera_batting %>%
  group_by(teamID) %>%
  summarize(
    span = paste(min(yearID), max(yearID), sep = "-"), 
    num_years = n_distinct(yearID), 
    num_teams = n_distinct(teamID), 
    BA = sum(H)/sum(AB), 
    tH = sum(H), 
    tHR = sum(HR), 
    tRBI = sum(RBI)
  ) %>%
  arrange(span)
```

```{r}
cabrera_batting %>%
  group_by(lgID) %>%
  summarize(
    span = paste(min(yearID), max(yearID), sep = "-"), 
    num_years = n_distinct(yearID), 
    num_teams = n_distinct(teamID), 
    BA = sum(H)/sum(AB), 
    tH = sum(H), 
    tHR = sum(HR), 
    tRBI = sum(RBI)
  ) %>%
  arrange(span)
```

???

Graph something here.
