---
title: "Exercises"
toc-title: "Outline"
toc: true
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
---


# 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_csv("https://euclid.nmu.edu/~joshthom/dat309/data/ATUS/atusrost_2025.dat") |>
  janitor::clean_names()
```

```{r}
#| eval: false
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%}
