``

options(repos = "https://cloud.r-project.org")

install.packages("tidyverse")
## Installing package into 'C:/Users/crist/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## package 'tidyverse' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\crist\AppData\Local\Temp\RtmpaMJ4Oc\downloaded_packages
library(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.5.0     ✔ 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(readr)
library(dplyr)
Data <- read_csv("C:/Users/crist/Downloads/Data Manipulation with Dplyr(in).csv")
## Rows: 6048 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): Indicator, Year, State, County, Race/Ethnicity, Sex, Cases
## dbl (1): FIPS
## num (1): Population
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Data_cleaned <- Data %>%
 mutate(
   Year = gsub(" \\(COVID-19 Pandemic\\)", "", Year),
   Year = as.numeric(Year),
   Cases = as.character(Cases), 
   Cases = ifelse(Cases == "Data suppressed" | Cases == "Data not available", NA_character_, Cases),
   Cases = as.numeric(Cases), 
   Population = as.numeric(Population)) %>%
 filter(!is.na(Population))
data <- read.csv("C:/Users/crist/Downloads/Data Manipulation with Dplyr(in).csv")

Data_cleaned <- Data %>%
  mutate(
    Year = gsub(" \\(COVID-19 Pandemic\\)", "", Year),
    Year = as.numeric(Year),
    Cases = as.character(Cases),
    Cases = ifelse(Cases == "Data suppressed" | Cases == "Data not available", NA_character_, Cases),
    Cases = as.numeric(Cases),
    Population = as.numeric(Population)
  ) %>%
  filter(!is.na(Population))
Data_cleaned <- Data_cleaned %>%
  mutate(Case_Rate = Cases / Population * 100000)

Selected_data <- Data_cleaned %>%
  select(Year, State, County, Case_Rate)

Filtered_data_2021 <- Selected_data %>%
  filter(Year == 2021)

Total_cases_by_location <- Data_cleaned %>%
  group_by(State, County) %>%
  summarise(Total_cases = sum(Cases, na.rm = TRUE))
## `summarise()` has grouped output by 'State'. You can override using the
## `.groups` argument.
Arranged_by_case_rate <- Selected_data %>%
  arrange(desc(Case_Rate))

print(Arranged_by_case_rate)
## # A tibble: 5,922 × 4
##     Year State County                                        Case_Rate
##    <dbl> <chr> <chr>                                             <dbl>
##  1  2020 IA    Des Moines-West Des Moines                         820.
##  2  2019 NC    Winston-Salem                                      794.
##  3  2021 WI    Milwaukee-Waukesha                                 725.
##  4  2020 IN    Indianapolis-Carmel-Anderson                       717.
##  5  2021 NC    Winston-Salem                                      606.
##  6  2019 NE-IA Omaha-Council Bluffs                               439.
##  7  2021 NC    Raleigh-Cary                                       412.
##  8  2019 IN    Indianapolis-Carmel-Anderson                       395.
##  9  2020 PA    Montgomery County-Bucks County-Chester County      392.
## 10  2020 FL    Miami-Miami Beach-Kendall                          361.
## # ℹ 5,912 more rows