Missing Values (NA) in R

Interactive beginner R tutorial on missing data: NA, is.na(), na.rm = TRUE, complete.cases(), na.omit() and filling gaps. Run real R in your browser.

Real datasets have holes, and R marks them NA. Handling them correctly is the difference between a right answer and NA. Everything below is a live R console — edit the code and press Run Code.

Watch: missing values (NA)

Finding gaps with is.na(), ignoring them with na.rm = TRUE, dropping rows, and filling them in.

Download the R script  ·  ▶ Practice in the playground — or edit and run each snippet below.

Find the gaps

NA means “not available”. is.na() flags them, and summing that count tells you how many:

NA is contagious

One gap makes the whole result NA. Add na.rm = TRUE to compute on what’s there:

Keep only complete rows

na.omit() drops any row with a gap; complete.cases() counts the whole ones:

Or fill the gaps

Sometimes you replace missing values (here with the median). Do this deliberately — it changes your data:

Your turn


Next: Reading data into R → — importing your own CSV files.