Cina
Cina

Reputation: 10199

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?

Upvotes: 3

Views: 1128

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 146164

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).

Upvotes: 7

Related Questions