How to remove row if it has a NA value in one certain column
The easiest solution is to use is.na()
:
df[!is.na(df$B), ]
which gives you:
A B C
1 NA 2 NA
2 1 2 3
4 1 2 3
there is an elegant solution if you use the tidyverse
!
it contains the library tidyr
that provides the method drop_na
which is very intuitive to read.
So you just do:
library(tidyverse)
dat %>% drop_na("B")
OR
dat %>% drop_na(B)
if B is a column name