0

I´m trying to remove from my data frame all rows containing N or more of NA value in R, could someone help?

For example, how could I remove rows in the following small matrix containing two or more NA? So that from this:

     V1  V2 V3 V4 V5 V6
[1,]  1 100  3 NA  1  3
[2,]  2  NA NA 12 45 NA
[3,]  3 300 NA NA  1  4
[4,] NA 400  3  5 23  8

I should get this:

     V1  V2 V3 V4 V5 V6
[1,]  1 100  3 NA  1  3
[4,] NA 400  3  5 23  8

Thanks a lot!

1 Answers1

1

You can get this with a one-liner.

df[!rowSums(is.na(df)) >= 2, ]
  V1  V2 V3 V4 V5 V6
1  1 100  3 NA  1  3
4 NA 400  3  5 23  8
G5W
  • 36,531
  • 10
  • 47
  • 80