vendredi 9 août 2019

Trying to drop NA rows when condition x is met in column 3

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

c <- c(1,2,3,4)
b <- c(NA,NA,NA,NA)
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 NA    a  

trying to get:

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

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.

Aucun commentaire:

Enregistrer un commentaire