3
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 eliminate the whole line when it exists NA
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
3
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 eliminate the whole line when it exists NA
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
3
The function filter
package dplyr
meets 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 studied the elements that are not NA
(!is.na
) of the variable a
Browser other questions tagged r
You are not signed in. Login or sign up in order to post.