Task 1:

Response:

For this task, I ran the tidy verse code to download the package. Then, I ran Inc2022 and Inc 2017 to download the data frame.

if(!require(tidyverse))install.packages("tidyverse")
## Loading required package: tidyverse
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidyverse)

Inc2022 <- read.csv("https://drkblake.com/wp-content/uploads/2024/02/Inc2022.csv")

Inc2017 <- read.csv("https://drkblake.com/wp-content/uploads/2024/02/Inc2017.csv")

Task 2:

Response: The left join function joins the data frames together. The head income ten code gave me the 10 data frames

Income <- left_join(Inc2022,
                        Inc2017,
                        by = join_by(GEOID == GEOID))
head(Income,10)
##         GEOID   District          County HHInc2022   Significance HHInc2017
## 1  4702190022 District 1 Cheatham County     59741    Significant     44091
## 2  4702190212 District 2 Cheatham County     73634    Significant     55247
## 3  4702190402 District 3 Cheatham County     89861 Nonsignificant     73802
## 4  4702190592 District 4 Cheatham County     73293    Significant     49731
## 5  4702190782 District 5 Cheatham County     78380    Significant     60793
## 6  4702190972 District 6 Cheatham County     92305    Significant     66750
## 7  4703790038 District 1 Davidson County     75038    Significant     56258
## 8  4703790228 District 2 Davidson County     54346    Significant     32487
## 9  4703790418 District 3 Davidson County     67953    Significant     49402
## 10 4703790608 District 4 Davidson County    106260    Significant     79381

Task 3:

Response:

I added a change variable to the income data that shows the difference in change between the difference in the 2022 district and 2017 district.

Income <- Income %>%
  mutate(Change = HHInc2022 - HHInc2017)

Task 4:

Response:

I added a variable “Level” to show the change in income data that organizes whats more or less than 100k between the 2022 and 2017 district in the first ten rows of the data frame.

  mutate(Level = case_when(HHInc2022 < 100000 ~ "<$100k",
                               HHInc2022 == 100000 ~ "No change",
                               HHInc2022 > 100000 ~ "100k+",
                              .default = "Error"))

Task 5:

Response:

In task five, I created the “LevelByCounty” code to show how many districts in each county are 100k+ or 100k

```{r}LevelByCounty <- Income} LevelByCounty <- group_by(LevelByCounty, County, Level) LevelByCounty <- summarize(LevelByCounty, Count = n()) LevelByCounty <- pivot_wider(LevelByCounty, names_from= Level, values_from =Count)


## Task 6:

## Response:

In task 6, I created a code called "RichDistricts", which displays all of the districts that are \$100k+ in the data frame.

```{r}RichDistricts <- Income}
RichDistricts <- Income %>% 
filter(Level=="$100k+")
head(RichDistricts, 10)

Task 7:

Response:

For this code, I used the rich districts data frame and put HHInc 2022 in descending order.

```{r}RichDistricts %>%} arrange(desc(HHInc2022)) head(RichDistricts,10)

```

Task 8:

Response:

When looking back over the results I got, I noticed that Williamson county was the highest rich district out of all the counties.