Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 211985

How to filter data with dplyr to retrieve NAs along with another value together?

$
0
0

I have a dataset that looks like this

X      Y      
121    Yes
122    No
123    NA
124    Yes
125    NA

How can I filter out the "Yes" values from column Y ? I only want 'No' and 'NA'

My Desired output is this

X      Y      
122    No
123    NA
125    NA

I've tried

data2 <- data %>% filter(Y != "Yes") #But I lose my NAs with this command.

& 

data2 <- data %>% filter(Y %in% c(is.na(Y), "No")  #Doesn't work

What am i doing wrong?


Viewing all articles
Browse latest Browse all 211985

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>