1

I have this type of data frame

DF
ID    V1         V2    V3
1     AXETINE    NA    2011
2     XOROX      INJ   NA
3     HERPESIN   NA    NA
4     ZOVIRAX    INJ   2015

and I would like to get this:

DF
ID    V1         V2    V3
1     AXETINE    NA    2011
4     ZOVIRAX    INJ   2015

I would like to get only rows with non NA values in V3

I have tried:

DF %>% na.omit(V3)

and

DF %>% select(!is.na(V3))

But this error occurs

Error: Must subset columns with a valid subscript vector.

I found a base R solution, but is there a dplyr one?

onhalu
  • 735
  • 1
  • 5
  • 17

1 Answers1

2

You can try:

library(dplyr)

DF %>% filter(!is.na(V3))
Duck
  • 39,058
  • 13
  • 42
  • 84