Cleaning

Set up

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   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── 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

Global Health Data

Data Import

df <- read_csv("data/global_climate_health.csv")
Rows: 14100 Columns: 30
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (5): country_code, country_name, region, income_level, date
dbl (25): record_id, year, month, week, latitude, longitude, population_mill...

ℹ 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 Inspect

colnames(df)
 [1] "record_id"                    "country_code"                
 [3] "country_name"                 "region"                      
 [5] "income_level"                 "date"                        
 [7] "year"                         "month"                       
 [9] "week"                         "latitude"                    
[11] "longitude"                    "population_millions"         
[13] "temperature_celsius"          "temp_anomaly_celsius"        
[15] "precipitation_mm"             "heat_wave_days"              
[17] "drought_indicator"            "flood_indicator"             
[19] "extreme_weather_events"       "pm25_ugm3"                   
[21] "air_quality_index"            "respiratory_disease_rate"    
[23] "cardio_mortality_rate"        "vector_disease_risk_score"   
[25] "waterborne_disease_incidents" "heat_related_admissions"     
[27] "healthcare_access_index"      "gdp_per_capita_usd"          
[29] "mental_health_index"          "food_security_index"         

Data CLeaning

Rename Data

df_clean <- df |>
  rename(country = country_name,
         air_quality = air_quality_index,
         gdp = gdp_per_capita_usd,
         healthcare = healthcare_access_index,
         respiratory_disease = respiratory_disease_rate) |>
  select(country, region, year, income_level, air_quality, respiratory_disease, healthcare, gdp)

glimpse(df_clean)
Rows: 14,100
Columns: 8
$ country             <chr> "United States", "United States", "United States",…
$ region              <chr> "North America", "North America", "North America",…
$ year                <dbl> 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 20…
$ income_level        <chr> "High", "High", "High", "High", "High", "High", "H…
$ air_quality         <dbl> 82, 6, 137, -3, 48, 157, 51, 5, 29, 22, -23, 73, 8…
$ respiratory_disease <dbl> 69.4, 70.0, 66.9, 47.0, 61.3, 80.2, 70.3, 48.0, 80…
$ healthcare          <dbl> 77.3, 83.6, 84.7, 84.3, 83.6, 78.0, 81.7, 86.7, 84…
$ gdp                 <dbl> 63627, 63627, 63627, 63627, 63733, 63733, 63733, 6…

Removed unused data

# This project only focus on the data during 2020 to 2024 because I want to explore the respiratory disease rate after Covid-19. The data in 2025 is not completed enouph so I just focus up to 2024.
df_clean2 <- df_clean |>
  filter(year >= 2020 & year <= 2024)

glimpse(df_clean2)
Rows: 6,525
Columns: 8
$ country             <chr> "United States", "United States", "United States",…
$ region              <chr> "North America", "North America", "North America",…
$ year                <dbl> 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 20…
$ income_level        <chr> "High", "High", "High", "High", "High", "High", "H…
$ air_quality         <dbl> 90, 10, 7, -3, 24, 26, 130, 83, 81, 77, 30, 96, 71…
$ respiratory_disease <dbl> 60.5, 41.9, 46.1, 68.0, 51.0, 63.1, 83.8, 61.3, 65…
$ healthcare          <dbl> 77.3, 86.6, 82.9, 81.6, 83.1, 84.4, 82.8, 86.4, 83…
$ gdp                 <dbl> 69979, 69979, 69979, 69979, 70085, 70085, 70085, 7…

Data Save

save(df_clean2, file = "data/clean.RData")