is.na()

is.na(x)
Returns: logical · Updated March 13, 2026 · Base Functions
na missing-values type-checking base

The is.na() function tests whether elements in an object are missing values (NA). It returns a logical vector of the same length as the input.

Syntax

is.na(x)

Parameters

ParameterTypeDefaultDescription
xany objectObject to test for missing values

Examples

Detecting NA values

x <- c(1, 2, NA, 4, NA, 6)

is.na(x)
# [1] FALSE FALSE  TRUE FALSE  TRUE FALSE

# Count NA values
sum(is.na(x))
# [1] 2

Working with different data types

# Character vector with NA
y <- c("apple", NA, "banana", NA)
is.na(y)
# [1] FALSE  TRUE FALSE  TRUE

# Data frame with NA
df <- data.frame(x = c(1, NA, 3), y = c("a", "b", NA))
is.na(df)
#        x     y
# [1] FALSE FALSE
# [2]  TRUE FALSE
# [3] FALSE  TRUE

Common Patterns

Removing NA values

x <- c(1, 2, NA, 4, NA, 6)
x[!is.na(x)]
# [1] 1 2 4 6

# Using na.omit
na.omit(x)
# [1] 1 2 4 6
# attr(,"na.action")
# [1] 3 5
# attr(,"class")
# [1] "omit"

Conditional handling of NA

x <- c(10, 20, NA, 40, 50)

# Replace NA with 0
ifelse(is.na(x), 0, x)
# [1] 10 20  0 40 50

# Use replace_na from tidyr
# replace_na(x, 0)

Using with data frames

df <- data.frame(
  name = c("Alice", "Bob", "Charlie"),
  score = c(85, NA, 92)
)

# Find rows with NA
df[is.na(df$score), ]
#     name score
# 2     Bob    NA

# Remove rows with NA
df[!is.na(df$score), ]
#     name score
# 1   Alice    85
# 3 Charlie    92

See Also