Find and count the Missing values From the entire Data Frame

In order to find the location of missing values and their count from the entire data frame pass the data frame name to the is.na() method. Let’s look into a program for finding and counting the missing values from the entire Data Frame.

R




# create a data frame
stats <- data.frame(player=c('A', 'B', 'C', 'D'),
                 runs=c(100, 200, 408, NA),
                 wickets=c(17, 20, NA, 5))
 
# find location of missing values
print("Position of missing values ")
which(is.na(stats))
 
# count total missing values
print("Count of total missing values  ")
sum(is.na(stats))


Output

[1] "Position of missing values "
[1] 8 11

[1] "Count of total missing values "
[1] 2

In this code we created a Data frame “stats” that holds data of cricketers with few missing values. To determine the location and count of missing values in the given data we used which(is.na(stats)) and sum(is.na(stats)) methods.

Count the number of Missing Values with summary

R




# create a data frame
stats <- data.frame(player=c('A', 'B', 'C', 'D'),
                    runs=c(NA, 200, 408, NA),
                    wickets=c(17, 20, NA, 8))
 
 
summary(stats)


Output:

    player               runs        wickets    
Length:4 Min. :200 Min. : 8.0
Class :character 1st Qu.:252 1st Qu.:12.5
Mode :character Median :304 Median :17.0
Mean :304 Mean :15.0
3rd Qu.:356 3rd Qu.:18.5
Max. :408 Max. :20.0
NA's :2 NA's :1

Here in each column at last it will shows the number of missing values parsant in each columns.

Count the number of Missing Values with colSums

R




# create a data frame
stats <- data.frame(player=c('A', 'B', 'C', 'D'),
                    runs=c(NA, 200, 408, NA),
                    wickets=c(17, 20, NA, 8))
 
colSums(is.na(stats))


Output:

 player    runs wickets 
0 2 1

How to Find and Count Missing Values in R DataFrame

In this article, we will be discussing how to find and count missing values in the R programming language.

Similar Reads

Find and Count Missing Values in the R DataFrame

Generally, missing values in the given data are represented with NA. In R programming, the missing values can be determined by is.na() method....

Find and count the Missing values From the entire Data Frame

In order to find the location of missing values and their count from the entire data frame pass the data frame name to the is.na() method. Let’s look into a program for finding and counting the missing values from the entire Data Frame....

Find and count the Missing values in one column of a Data Frame

...

Find and count missing values in all columns in Data Frame

...

Contact Us