Code
library(tidyverse)
library(here)
# Sys.setlocale("LC_TIME", "en_US.UTF-8")
# Uncomment above line, if computer's locale is not in US.
AQI_tbl <- here("data", "raw", "AQI.csv") %>%
read_csv(locale = locale(encoding = "GBK"))
AQI_tbl <- AQI_tbl %>%
mutate(TIME = ymd_hm(TIME)) %>%
mutate(month_of_obs = month(TIME, label =T)) %>%
mutate(season = case_when(
month_of_obs >= 3 & month_of_obs < 6 ~ "Spring",
month_of_obs >=6 & month_of_obs < 9 ~ "Summer",
month_of_obs >=9 & month_of_obs < 12 ~ "Autumn",
month_of_obs = 12 | month_of_obs <3 ~ "Winter",
.default = "NA"
)
) %>%
mutate(time_of_obs = hour(TIME)) %>%
mutate(time_of_day = case_when(
time_of_obs >= 6 & time_of_obs < 10 ~ "Morning Peak",
time_of_obs >= 10 & time_of_obs < 16 ~ "Off Peak (Day)",
time_of_obs >= 16 & time_of_obs < 19 ~ "Evening Peak",
time_of_obs >= 19 | time_of_obs < 6 ~ "Night",
.default = "NA"
)
)%>%
mutate(AQI = as.numeric(AQI)) %>%
mutate(SITEID = as.character(SITEID)) %>%
mutate(AIRQUALITY = factor(AIRQUALITY))