I would like to count the NA of a set of variables with a for loop.
confounders<-c("Age", "Sex", "Race", "education")
missings = list()
for (var in confounders) { missings[[var]] = with(data_all, sum(is.na(var[[1]])))}
missings
I only get the output zero for every variable, which is incorrect:
> missings
$Age
[1] 0
$Sex
[1] 0
$Race
[1] 0
$education
[1] 0
> with(data_all, sum(is.na(education)))
[1] 55