How to find the percentage of missing values in a dataframe in R?
In this article, let’s discuss how to find the percentage of missing values (NAs) in R Programming Language. Percentage of NAs denote the fraction of data cells that are not defined by a definite cell value. The percentage of NA values can be calculated using the following formula :
Percentage of NAs = (Number of cells with NA) * 100 /(Total number of cells)
Method 1: The total number of cells can be found by using the product of the inbuilt dim() function in R, which returns two values, each indicating the number of rows and columns respectively.
The number of cells with NA values can be computed by using the sum() and is.na() functions in R respectively. The following code snippet first evaluates each data cell value to return a logical value of true if there is a missing value and false, if not. Then, the summation of these NA values is done using sum() function.
 "Original data frame" C1 C2 C3 1 1 NA A 2 2 NA V 3 NA 3 j 4 0 8 y  "Total number of cells "  12  "Missing value cells"  3  "Percentage of missing values' cells"  25
Method 2: We can simply use the mean() function in R, to carry out the division of missing cells by the total number of cells. is.na() function is first used to determine whether the data cell value is true or false and then the mean() method is applied over it. The time complexity required is polynomial with respect to the size of data frame, since each data cell value is evaluated.
 "Original data frame" C1 C2 C3 C4 1 1 NA A NA 2 2 NA V NA 3 NA 3 j NA 4 0 8 y NA  "percentage of missing values"  43.75