How to Report NA Values in a Data Frame in R Programming (Example Code)

In this tutorial, I’ll show how to visualize and count missing values in R programming.

Creating Example Data

my_df <- data.frame(v = c(1, 5, NA, 3, 1),
                    w = 1:5,
                    x = c("A", "C", NA, "C", "B"),
                    y = c(0, 0, NA, NA, 0),
                    z = c(9, 8, 7, 6, NA))
my_df
#    v w    x  y  z
# 1  1 1    A  0  9
# 2  5 2    C  0  8
# 3 NA 3 <NA> NA  7
# 4  3 4    C NA  6
# 5  1 5    B  0 NA

Example: Get Number of NA Values for Each Column

colSums(is.na(data))        # Counting missings
# v w x y z 
# 1 0 1 2 1

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