summary(all_cases$coi_final)

And what I got back made zero sense. Basically, all valid categories had disappeared into NA's.

| Very Low | Low | Moderate | High | Very High | Unknown | NA's | | — — — — — | — — -| — — — — — | — — — | — — — — — -| — — — — -| — — — -| | 0 | 0 | 0 | 0 | 0 | 17 | 56159 |

Naturally, I asked ChatGPT for help. It suggested a very elaborate fix:

mutate( coi_final = as.character(coi_final), coi_final = str_squish(coi_final), coi_final = str_replace_all(coi_final, "\\u00A0", " "), coi_final_low = tolower(coi_final), coi_final_low = recode(coi_final_low, "1" = "very low", "2" = "low", "3" = "moderate", "4" = "high", "5" = "very high"), coi_key = gsub("[^a-z]", "", coi_final_low), coi_final_clean = case_when( coi_key == "verylow" ~ "Very Low", coi_key == "low" ~ "Low", coi_key == "moderate" ~ "Moderate", coi_key == "high" ~ "High", coi_key == "veryhigh" ~ "Very High", TRUE ~ NA_character_ ), coi_final = if_else(is.na(coi_final_clean), "Unknown", coi_final_clean), coi_final = factor(coi_final, levels = c("Very Low","Low","Moderate", "High","Very High","Unknown"), ordered = TRUE) )

Impressive? Yes. Efficient? Not so much.

Instead, I leaned on 15 years of experience coding in R. Even though I was tired, I knew the real issue was simply how factors and characters were being handled. My solution was clean, short, and to the point:

all_cases <- all_cases %>% mutate( coi_final = as.factor( ifelse(is.na(all_cases$coi_final), "Unknown", as.character(all_cases$coi_final)) ), coi_final = factor(coi_final, levels = c("Very Low","Low","Moderate", "High","Very High","Unknown")) )

Here's the thing: in data science, efficiency matters. Not just because shorter code is easier to read, but because when you're building pipelines for predictive modeling, every unnecessary step is a potential drag on performance, reproducibility, and debugging.

The lesson?

Efficiency matters — especially when you're scaling up for modeling or deploying pipelines.

Basic R skills are still powerful — sometimes the simple tools solve the problem better than complex code.

Creativity counts — not every "fancy" solution is the best one. Sometimes, the best solution is the one that makes your future self (and your collaborators) grateful for its clarity.

At the end of the day, tools like ChatGPT are great partners. But we, as coders, should still be the boss. 😉