R Warning “NA introduced by coercion” — Troubleshooting Guide (NYC)

This warning appears when R tries to convert text to numbers and fails. Students at NYU, Columbia, and Baruch often see this after importing messy spreadsheets.For broader graduate statistics and software support, visit our main page: Statistics Tutoring NYC.

Why this warning happens

You ran something like:

df$score_num <- as.numeric(df$score)

R found values that cannot be converted, such as:

  • “N/A”
  • “missing”
  • “85*”
  • “1,200”
  • “$500”

How to diagnose the issue

1. Identify the bad values

bad <- df$score[is.na(as.numeric(df$score))]
unique(bad)

2. Look for patterns

  • Currency symbols
  • Commas
  • Spaces
  • Text codes

How to fix it

Option 1 — Use parse_number()

library(readr)
df$score_num <- parse_number(df$score)

Option 2 — Remove non-numeric characters

df$clean <- gsub("[^0-9.]", "", df$score)
df$score_num <- as.numeric(df$clean)

Option 3 — Recode text codes

Convert “N/A” or “missing” to NA before conversion.

Need help?

If your dataset is large or messy, cleaning it manually can take hours. You can get direct help with R data cleaning for homework, exams, or projects.

Call or text: 646‑543‑0832
WhatsApp: 206‑384‑1336
Email: tutor@mytutornyc.com