To count the number of NA values in a column, you can use the sum() function as follows:
sum(is.na(df$col))
For example:
In the following data frame:
df <- data.frame(A = sample(c(1:20), 10),
B = sample(c(TRUE, FALSE,NA), 10, rep = TRUE))
df
A B
1 7 NA
2 12 FALSE
3 9 TRUE
4 11 FALSE
5 20 NA
6 17 FALSE
7 3 NA
8 10 FALSE
9 13 NA
10 18 NA
To count the number of NA values in column ‘B’:
sum(is.na(df$B))
[1] 5