So I have a dataframe which has multiple columns and many rows. I want to be able to assign the number of NAs across all the columns row by row to a new variable (NACount). Something like this:
Col1 Col2 Col3 Col4 NACount
A A B NA 1
B B NA NA 2
I built a loop to do this but my data set is huge so the loop takes forever! Here is my code:
for(i in 1:nrow(dat)){
temp = which(!is.na(dat[i,]))
dat$NACount[[i]] = length(temp)
}
Please help me find an easier approach/way to do this!
Thanks so much!