0

Trying to Drop NA Rows which fulfill condition df$e == 'a'

c <- c(1,2,3,4)
b <- c(NA,NA,NA,'f')
e <- c('e','a','e','a')
df <- tibble(c,b,e)


# A tibble: 4 x 3
      c b     e    
  <dbl> <lgl> <chr>
1     1 NA    e    
2     2 NA    a    
3     3 NA    e    
4     4 f     a  

trying to get:

# A tibble: 4 x 3
      c b     e    
  <dbl> <lgl> <chr>
1     1 NA    e       
3     3 NA    e  
4     4 f     a 

I have tried variations of df <- which(df$e == 'a' & is.na(df$b) == TRUE) and df %>% ifelse(df$e == 'a', drop_na('b')) with no success.

Luke Holcomb
  • 157
  • 7
  • 3
    google "subsetting data.frames R" and try a simply one `df[ df$e != "a", ]` – Roman Aug 09 '19 at 14:31
  • @Jimbou edited above for clarity. So my issue is that I need to filter both conditions, not just one. so when I try `df[df$e != 'a' & is.na(df$b) == TRUE,]` returns the same result as `df[df$e != 'a',]` – Luke Holcomb Aug 09 '19 at 17:37
  • Solution `df[ !is.na(df$b) | (df$e != 'a'), ]` – Luke Holcomb Aug 09 '19 at 18:26

0 Answers0