I have a data frame as follows:
col1 col2 col3
1 23 17 NA
2 55 NA NA
3 24 12 13
4 34 23 12
I'm interested in finding the number of rows in col2 and col3 with NAs.
I was surprised that the following code only gave me 4 instead of 2:
numNAs <- rowSums(is.na(all[,2:3]))
Please help.
This gives the number of rows that contain any
NA
values in column 2 or 3:Another solution adding columns 2 and 3:
Another solution:
Another short solution:
where
dat
is the name of your data frame.