is.na Function in R (3 Examples)

This article shows how to use the is.na() function in the R programming language.

Example Data

x <- c(4, 1, NA, 7, 2, NA, 5)   # Create example vector

Return Logical Vector with is.na Function

is.na(x)                        # Return logical vector
# FALSE FALSE  TRUE FALSE FALSE  TRUE FALSE

Remove NA Values from Vector

x[!is.na(x)]                    # Remove NA values
# 4 1 7 2 5

Replace NA with 0 in R

x[is.na(x)] <- 0                # Replace NA with 0
x
# 4 1 0 7 2 0 5

Video Examples: Handling NA Values in R

YouTube

By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top