Consider the dataframe:
data<-data.frame(a=c(1,3,4,5,6,NA,6,NA),b=c(1,NA,NA,4,6,7,NA,1))
I want to delete the entire line when NA
exists in variable 'a' . So, what I hope is:
data
a b
1 1 1
2 3 NA
3 4 NA
4 5 4
5 6 6
6 6 NA
Consider the dataframe:
data<-data.frame(a=c(1,3,4,5,6,NA,6,NA),b=c(1,NA,NA,4,6,7,NA,1))
I want to delete the entire line when NA
exists in variable 'a' . So, what I hope is:
data
a b
1 1 1
2 3 NA
3 4 NA
4 5 4
5 6 6
6 6 NA
The filter
function of the dplyr
package fulfills what you want
library(dplyr)
data %>%
filter(!is.na(a))
a b
1 1 1
2 3 NA
3 4 NA
4 5 4
5 6 6
6 6 NA
In this case I have filtered the elements that are not NA
( !is.na
) of the variable a