I am trying to count NA values from every column in data frame like this
a = c('a', 'b', NA)
b = c('a', NA, NA)
c = c(NA, NA, NA)
data = data.frame(cbind(a, b, c))
This works
sum(is.na(data$a))
But when i tried using LOOP
for(i in data[, 1:3]) {
k=sum(is.na(data$i))
cat(k, '\n')
}
I am getting
Warning messages:
1: In is.na(data$i) :
is.na() applied to non-(list or vector) of type 'NULL'
How do I fix it?