How to Get the Number of Non-NA Values in R (Example Code)

This tutorial explains how to get the number of non-NA values in the R programming language.

Exemplifying Data

x <- c("x", NA, "y", NA, "x", "x", "z", NA, "z", "y", NA)  # Constructing a vector with NAs
x
#  [1] "x" NA  "y" NA  "x" "x" "z" NA  "z" "y" NA

Example: Counting the Number of Non-NA Values Using sum() & is.na() Functions

sum(!is.na(x))                                             # Counting non-NA values
# [1] 7

Related Tutorials & Further Resources

You may find some additional tutorials on topics such as numeric values, counting, and groups below:

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