Task 1:

This code tells R to read the data and the tidyverse package makes the data tidy, which is how we like it as data analysts.

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:

This code joined the ’22(from) and ’17(to) data together with they key column variable GEOID.

Income <- left_join(Inc2017,
                        Inc2022,
                        by = join_by(GEOID == GEOID))

Task 3: Using the mutate function, I was able to combine the data into one graph and find the change between 2022 and 2017.

Income <- Income %>% 
  mutate(Change = HHInc2022 - HHInc2017)
head(Income, 10)
##         GEOID HHInc2017   District          County HHInc2022   Significance
## 1  4702190022     44091 District 1 Cheatham County     59741    Significant
## 2  4702190212     55247 District 2 Cheatham County     73634    Significant
## 3  4702190402     73802 District 3 Cheatham County     89861 Nonsignificant
## 4  4702190592     49731 District 4 Cheatham County     73293    Significant
## 5  4702190782     60793 District 5 Cheatham County     78380    Significant
## 6  4702190972     66750 District 6 Cheatham County     92305    Significant
## 7  4703790038     56258 District 1 Davidson County     75038    Significant
## 8  4703790228     32487 District 2 Davidson County     54346    Significant
## 9  4703790418     49402 District 3 Davidson County     67953    Significant
## 10 4703790608     79381 District 4 Davidson County    106260    Significant
##    Change
## 1   15650
## 2   18387
## 3   16059
## 4   23562
## 5   17587
## 6   25555
## 7   18780
## 8   21859
## 9   18551
## 10  26879

Task 4: This code added a column called level, then took my instructions regarding INC2022 and put either 100k+ if 22 income was greater than 100,000 and <100k when it was less.

Income <- Income %>% 
  mutate(Level = case_when(HHInc2022 < 100000 ~ "<100k+",
                               HHInc2022 == 100000 ~ "No change",
                               HHInc2022 > 100000 ~ "100k+",
                               .default = "Error"))
head(Income, 10)
##         GEOID HHInc2017   District          County HHInc2022   Significance
## 1  4702190022     44091 District 1 Cheatham County     59741    Significant
## 2  4702190212     55247 District 2 Cheatham County     73634    Significant
## 3  4702190402     73802 District 3 Cheatham County     89861 Nonsignificant
## 4  4702190592     49731 District 4 Cheatham County     73293    Significant
## 5  4702190782     60793 District 5 Cheatham County     78380    Significant
## 6  4702190972     66750 District 6 Cheatham County     92305    Significant
## 7  4703790038     56258 District 1 Davidson County     75038    Significant
## 8  4703790228     32487 District 2 Davidson County     54346    Significant
## 9  4703790418     49402 District 3 Davidson County     67953    Significant
## 10 4703790608     79381 District 4 Davidson County    106260    Significant
##    Change  Level
## 1   15650 <100k+
## 2   18387 <100k+
## 3   16059 <100k+
## 4   23562 <100k+
## 5   17587 <100k+
## 6   25555 <100k+
## 7   18780 <100k+
## 8   21859 <100k+
## 9   18551 <100k+
## 10  26879  100k+

Task 5: I used the code to create a new data set called LevelbyCounty by using the data from Income. I then used group_by code to tell r to group my new data set by County, Level, and 2022 income. Lastly, using the summarize function, I told r to tell me how many districts make over and under 100K. The head function let me see the first 10 rows to make sure the code worked correctly.

LevelbyCounty <- Income
head(LevelbyCounty, 20)
##         GEOID HHInc2017    District          County HHInc2022   Significance
## 1  4702190022     44091  District 1 Cheatham County     59741    Significant
## 2  4702190212     55247  District 2 Cheatham County     73634    Significant
## 3  4702190402     73802  District 3 Cheatham County     89861 Nonsignificant
## 4  4702190592     49731  District 4 Cheatham County     73293    Significant
## 5  4702190782     60793  District 5 Cheatham County     78380    Significant
## 6  4702190972     66750  District 6 Cheatham County     92305    Significant
## 7  4703790038     56258  District 1 Davidson County     75038    Significant
## 8  4703790228     32487  District 2 Davidson County     54346    Significant
## 9  4703790418     49402  District 3 Davidson County     67953    Significant
## 10 4703790608     79381  District 4 Davidson County    106260    Significant
## 11 4703790798     40220  District 5 Davidson County     71189    Significant
## 12 4703790988     50871  District 6 Davidson County     82996    Significant
## 13 4703791178     46594  District 7 Davidson County     72500    Significant
## 14 4703791368     39885  District 8 Davidson County     62232    Significant
## 15 4703791558     39769  District 9 Davidson County     54322    Significant
## 16 4703791748     47270 District 10 Davidson County     58338    Significant
## 17 4703791938     57086 District 11 Davidson County     73158    Significant
## 18 4703792128     61720 District 12 Davidson County     85559    Significant
## 19 4703792318     46435 District 13 Davidson County     63110    Significant
## 20 4703792508     53068 District 14 Davidson County     64380    Significant
##    Change  Level
## 1   15650 <100k+
## 2   18387 <100k+
## 3   16059 <100k+
## 4   23562 <100k+
## 5   17587 <100k+
## 6   25555 <100k+
## 7   18780 <100k+
## 8   21859 <100k+
## 9   18551 <100k+
## 10  26879  100k+
## 11  30969 <100k+
## 12  32125 <100k+
## 13  25906 <100k+
## 14  22347 <100k+
## 15  14553 <100k+
## 16  11068 <100k+
## 17  16072 <100k+
## 18  23839 <100k+
## 19  16675 <100k+
## 20  11312 <100k+
LevelbyCounty <- group_by(LevelbyCounty, County, Level, HHInc2022)

LevelbyCounty <- summarize(LevelbyCounty, Count = n())
## `summarise()` has grouped output by 'County', 'Level'. You can override using
## the `.groups` argument.
head(LevelbyCounty, 10)
## # A tibble: 10 × 4
## # Groups:   County, Level [2]
##    County          Level  HHInc2022 Count
##    <chr>           <chr>      <int> <int>
##  1 Cheatham County <100k+     59741     1
##  2 Cheatham County <100k+     73293     1
##  3 Cheatham County <100k+     73634     1
##  4 Cheatham County <100k+     78380     1
##  5 Cheatham County <100k+     89861     1
##  6 Cheatham County <100k+     92305     1
##  7 Davidson County 100k+     106260     1
##  8 Davidson County 100k+     110739     1
##  9 Davidson County 100k+     117294     1
## 10 Davidson County 100k+     117474     1

Task 6: This code created a new data set called RichDistricts and filtered the information by level and who made more than 100K(per household).

RichDistricts <- LevelbyCounty
RichDistricts <- filter(RichDistricts, Level == "100k+")
head(RichDistricts, 10)
## # A tibble: 10 × 4
## # Groups:   County, Level [3]
##    County            Level HHInc2022 Count
##    <chr>             <chr>     <int> <int>
##  1 Davidson County   100k+    106260     1
##  2 Davidson County   100k+    110739     1
##  3 Davidson County   100k+    117294     1
##  4 Davidson County   100k+    117474     1
##  5 Davidson County   100k+    120206     1
##  6 Davidson County   100k+    161370     1
##  7 Robertson County  100k+    106058     1
##  8 Rutherford County 100k+    102862     1
##  9 Rutherford County 100k+    103006     1
## 10 Rutherford County 100k+    105750     1

Task 7: Using the pipe operator, I asked r to sort RichDistricts by 2022 income information, specifically in descending order.

RichDistricts <- RichDistricts %>% 
  arrange(desc(HHInc2022))

Task 8:

One thing I noticed while working through this information, is that wealth in Tennessee, much like the rest of the nation, is very concentrated. Only one county, Williamson, has more districts making over 100K per household than those making less than 100K. Even in places like Davidson county, the majority of districts are on the <100K end of the income spectrum.