---
title: "Exercises"
toc-title: "Outline"
toc: true
theme: darkly
format:
  html: 
    code-overflow: wrap
    toc: true
    toc-title: "Table of Contents"
    code-fold: true
include-in-header:
  - text: |
      <style>
      .cell-output-stdout code {
        word-break: break-wor !important;
        white-space: pre-wrap !important;
      }
      </style>
execute:
  warning: false
  message: false
---


1. How many different planes are there in the `flights` data?  How many airports?

2. Did every plane visit every airport?


3. Create a data frame of the most delayed flight (departure) from each airport.

# Categorize continuous data with `cut()`

`cut` divides the range of x into intervals and codes the values in x according to which interval they fall. 

Use [`cut()`](https://rdrr.io/r/base/cut.html)

```{r}
library(tidyverse)
atus <- read_rds("/users/josh/google drive/teaching/dat309/week2/ATUS2/ATUS_data.RDS") |> 
  janitor::clean_names()

df <- mutate(atus, work_level = cut(act_work,
  breaks = c(0,60,60*9,60*24),
  labels = c("low","medium","high")),
  .before = 1)

```

### Exercise with `cut()`

4. Re-create a nice-looking plot of the *ATUS* data that uses `cut()` to create a category of based on the numerical data of `act_work`:

![](cat-cut.png){width=50%}

Which is the better plot? 

![](cat-cut2.png){width=50%}