# Install and load the tidyverse packages if not already installed if (!requireNamespace("tidyverse", quietly = TRUE)) { install.packages("tidyverse") } library(tidyverse) # Read the raw data from the CSV file raw_data <- read_csv("measuring_distress.csv") # Rename columns and make them tidy cleaned_data <- raw_data %>% rename( Geography = "2022 Per Capita Money Income (ACS 5-year PCMI)", Unemployment = "24 Month Unemployment", Unemployment_Threshold_Calculation = "Threshold Calculation", BEA_PCPI = "BEA PCPI", BEA_PCPI_Threshold_Calculation = "Threshold Calculation.1", ACS_PCMI = "ACS 5-Year PCMI", ACS_PCMI_Threshold_Calculation = "Threshold Calculation.2" ) %>% mutate(across(everything(), as.character)) %>% # Convert all columns to character mutate( Unemployment = as.numeric(Unemployment), Unemployment_Threshold_Calculation = as.numeric(Unemployment_Threshold_Calculation), BEA_PCPI = as.numeric(gsub("\\$", "", BEA_PCPI)), BEA_PCPI_Threshold_Calculation = as.numeric(gsub("\\$", "", BEA_PCPI_Threshold_Calculation)), ACS_PCMI = as.numeric(gsub("\\$", "", ACS_PCMI)), ACS_PCMI_Threshold_Calculation = as.numeric(gsub("\\$", "", ACS_PCMI_Threshold_Calculation)) ) # Convert numeric columns to numeric format # Export the cleaned dataset to a new CSV file write_csv(cleaned_data, "cleaned_measuring_distress.csv")