Search code examples
rrowmissing-data

find the row with highest number of NA value in R


I have datafrom

df
1 a c  NA NA
2 a a  a  NA
3 c NA NA NA

Firstly, I want to find which row has the highest number of NA value. I am also interested to find rows with the condition of having more than 2 NA values.
How can I do it in R?


Solution

  • na_rows = rowSums(is.na(df)) gives the count of NA by row. You can then look at which.max(na_rows) and which(na_rows > 2).