Task 1: Installing, loading, and making date frames

Response: The code that was ran reads the .csv file which is either a google sheet or excel file. The library is where the code is stored and there is a code to load and install the packages.

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: Merge the two data sets and make a new one called income

Response: The code here merges the two data frames and is joined together by the GEOID’s

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

Task 3: Add a tabel that adds a change and what the change is between the data frames

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

Task 4: Write a code that adds a variable called Level

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
##    Change
## 1   15650
## 2   18387
## 3   16059
## 4   23562
## 5   17587
## 6   25555
## 7   18780
## 8   21859
## 9   18551
## 10  26879
Income <- Income %>% 
  mutate(level = case_when(HHInc2022 > 99999 ~ "$100K+",
                           HHInc2017 < 100000 ~ "<$100K",
                           .default = "Error"))

Task 5: Create data date frame called Levelbycounty

LevelbyCounty <- Income %>%
  group_by(County, level) %>%
  summarize(Count = n()) %>%
  pivot_wider(names_from = level,
              values_from = Count)
## `summarise()` has grouped output by 'County'. You can override using the
## `.groups` argument.
head(LevelbyCounty,10) 
## # A tibble: 7 × 3
## # Groups:   County [7]
##   County            `<$100K` `$100K+`
##   <chr>                <int>    <int>
## 1 Cheatham County          6       NA
## 2 Davidson County         29        6
## 3 Robertson County        11        1
## 4 Rutherford County       18        3
## 5 Sumner County           10        2
## 6 Williamson County        2       10
## 7 Wilson County           15       10

Task 6:

RichDistricts <- Income %>%
  filter(level == "$100K+")
head(RichDistricts,10)
##         GEOID    District            County HHInc2022   Significance HHInc2017
## 1  4703790608  District 4   Davidson County    106260    Significant     79381
## 2  4703794218 District 23   Davidson County    117474    Significant     86768
## 3  4703794408 District 24   Davidson County    110739    Significant     79959
## 4  4703794598 District 25   Davidson County    120206    Significant     90998
## 5  4703796460 District 34   Davidson County    161370    Significant    128421
## 6  4703796650 District 35   Davidson County    117294    Significant     99666
## 7  4714791098  District 6  Robertson County    106058    Significant     65179
## 8  4714991480  District 8 Rutherford County    102862    Significant     75875
## 9  4714991670  District 9 Rutherford County    103006    Significant     77481
## 10 4714992620 District 14 Rutherford County    105750 Nonsignificant     95708
##    Change  level
## 1   26879 $100K+
## 2   30706 $100K+
## 3   30780 $100K+
## 4   29208 $100K+
## 5   32949 $100K+
## 6   17628 $100K+
## 7   40879 $100K+
## 8   26987 $100K+
## 9   25525 $100K+
## 10  10042 $100K+

Task 7:

RichDistricts <- RichDistricts %>%
  arrange(desc(HHInc2022))
head(RichDistricts,10)
##         GEOID    District            County HHInc2022   Significance HHInc2017
## 1  4718791328  District 7 Williamson County    181709    Significant    150106
## 2  4718791138  District 6 Williamson County    178665    Significant    154149
## 3  4703796460 District 34   Davidson County    161370    Significant    128421
## 4  4718790948  District 5 Williamson County    159737    Significant    121622
## 5  4718791708  District 9 Williamson County    144924    Significant    117526
## 6  4718993040 District 16     Wilson County    125785    Significant     74528
## 7  4718990570  District 3     Wilson County    125324    Significant     80577
## 8  4718790758  District 4 Williamson County    124237 Nonsignificant    127552
## 9  4718790378  District 2 Williamson County    123609    Significant    101687
## 10 4718990380  District 2     Wilson County    120302    Significant     98846
##    Change  level
## 1   31603 $100K+
## 2   24516 $100K+
## 3   32949 $100K+
## 4   38115 $100K+
## 5   27398 $100K+
## 6   51257 $100K+
## 7   44747 $100K+
## 8   -3315 $100K+
## 9   21922 $100K+
## 10  21456 $100K+

Task 8: In the data,saw how much different parts of Middle Tennessee make in a given year. Also was a bit surprised by how much some county’s income is over 100K. On top of how much the income has changed from 2017 to 2022 with some being around 40K difference.