Menu
Coddy logo textTech

Missing Values: NA

Part of the Fundamentals section of Coddy's R journey — lesson 10 of 78.

In real-world data analysis, you'll often encounter situations where information is missing or unavailable. R provides a special value called NA to handle these cases.

NA stands for "Not Available" and represents a missing or undefined value. It's a special logical constant that serves as a placeholder when data is unknown or absent. Unlike other data types you've learned, NA doesn't represent any actual value - it represents the absence of a value.

You can assign NA to any variable just like you would with other values:

missing_data <- NA
unknown_score <- NA

This is particularly useful when you're working with datasets where some information might be incomplete. For example, if you're collecting user information but someone hasn't provided their age, you can store NA instead of leaving the variable empty or using an arbitrary number like 0, which could be misleading.

challenge icon

Challenge

Easy

Create variables to represent missing information in a student database. First, create a variable called student_age and assign it NA to represent an unknown age. Then create a variable called test_score and assign it NA to represent a missing test score. Finally, create a variable called graduation_year and assign it NA to represent an unknown graduation year.

After creating all three variables, use the print() function to display each variable in this exact order: student_age, test_score, and graduation_year.

Cheat sheet

R uses NA (Not Available) to represent missing or undefined values. NA is a special logical constant that serves as a placeholder when data is unknown or absent.

You can assign NA to variables:

missing_data <- NA
unknown_score <- NA

Using NA is preferable to using arbitrary values like 0 or empty strings when data is genuinely missing, as it clearly indicates the absence of information.

Try it yourself

# TODO: Write your code here
# Create the three variables with NA values
# Then print each variable in the specified order
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals