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
#  [1] "x" NA  "y" NA  "x" "x" "z" NA  "z" "y" NA

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

sum(!                                             # 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