---
title: 'Lab 4: Introduction to Data Wrangling'
format:
  html:
    embed-resources: true
knitr:
  opts_chunk:
    message: false
---

###### Question

::: question
Use the code below to:

1. Load the tidyverse package.
2. Import the `acs12` data from the openintro package, and assign it to an object called `acs_df` in your environment.
:::


```{r unnamed-chunk-3}
#| document: show
#| code-fold: show
#| message: false
#| warning: false
library(tidyverse)
acs_df <- openintro::acs12
```

```{r unnamed-chunk-4}
#| document: show
subset_df <- acs_df |>
  select(income, age, gender, hrs_work, time_to_work) |>
  filter(gender == "female")
```

###### Question

::: question
Using the above code as an example, use the `select()` function to keep the variables `married`, `race`, and `edu`. Use the template code below as a guide to help you select the columns.
:::


```{r unnamed-chunk-7}
#| eval: false
#| document: template
# CODE TEMPLATE
acs_df |> 
  select(________)
```

###### Question

::: question
Select the following variables: `citizen`, `time_to_work`, and `lang`.
:::


###### Question

::: question
Use the template below to only keep observations where `time_to_work` is greater than or equal to 35 minutes **and** `income` is strictly greater than fifty thousand dollars (\$50000).
:::


```{r unnamed-chunk-15}
#| eval: false
#| document: template
# CODE TEMPLATE
acs_df |>
  filter( ______  & _______  )
```

###### Question

::: question
Use the `mutate()` command to generate a new variable in the `subset_df` data frame that measures age in months instead of years.
:::


###### Question

::: question
Use the template below to arrange the `subset_df` data frame by the `hrs_work` variable.
:::


```{r unnamed-chunk-22}
#| eval: false
#| document: template
# CODE TEMPLATE
subset_df |>
  arrange(_________)
```

###### Question

::: question
Generate code that will arrange the `subset_df` data frame by `time_to_work` in descending order.
:::


###### Question

::: question
Using the template below, select the variables `hrs_work`, `income`, and `married`, and keep observations where `income` is less than \$ 30,000.
:::


```{r unnamed-chunk-26}
#| eval: false
#| document: template
# CODE TEMPLATE
acs_df |>
  select() |>
  filter()
```

###### Question

::: question
Use the pipe operator to generate a variable that measures income in units of \$10,000 and then arranges the data by `hrs_work`. Then select these two variables.
:::


