In R, NA stands for “Not Available”. It is an indicator of missing values in a vector or data frame.
The is.na() function checks if missing data is available in a R dataset. The function returns TRUE if the data is NA; else returns FALSE. This guide shows how to use the is.na() function in R.
Syntax
is.na(x)
Argument
- x = a vector or a data frame
Example 1: Using is.na() function in a vector
#creating a vector
x <- c(12,NA,23,NA,27,13,NA,15)
is.na(x)
Output
[1] FALSE TRUE FALSE TRUE FALSE FALSE TRUE FALSE
In the above example, is.na() checks each element of the vector and returns TRUE if the element is a NA value.
Example 2: Using is.na() function in a dataframe
#creating a data frame
x <- data.frame(CarName=c('Honda','Toyota',NA,'Audi'),
Mileage=c(NA,25,33,NA),
Cylinders=c(NA,NA,6,5))
is.na(x)
Output
In the above example, is.na() checks each column and row of the data frame and returns TRUE if the element is a NA value.