Count of missing values of column in R is calculated by using sum(is.na()). Let’s see how to
- Get count of Missing value of each column in R
- Get count of Missing value of single column in R
Let’s first create the dataframe
df1 = data.frame(Name = c('George','Andrea', 'Micheal','Maggie','Ravi','Xien','Jalpa'), Mathematics_score=c(45,78,44,89,66,NaN,NaN), Science_score=c(56,52,NA,88,33,90,47)) df1
so the dataframe will be
Get count of missing values of all columns in R:
Sapply along with sum(is.na()) calculates count of missing values of all the column in R
# Missing value of all the column in R sapply(df1, function(x) sum(is.na(x)))
Result:
Get count of missing values of single columns in R:
Count missing values of column “mathematics_score” is calculated
# Missing value of single column sum(is.na(df1$Mathematics_score))
Result:
2