# 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 |

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 |

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: