Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter on blanks or a certain value with R

I have a dataset I am taking from a public website using their R package and I have the full list. I am interested in a particular region of England, which is covered in the field ParentName. So, this below works:

mydata <- df[df$ParentName %in% c("South East region"),]

However, if I want to compare this to England overall, it does not have a value in ParentName, so I am looking to essentially filter on where ParentName is NULL/blank OR is the string value "South East region"

How might I go about that? I am extremely new to R and have had no training, so it is probably something very simple, but I can only seem to find guides on how to get rid of blanks! Thanks all.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried using || but I don’t think this works, or I am doing it wrong.

>Solution :

If I understood correctly, this will work:

mydata <- 
 df[(df$ParentName == "South East region")|(df$ParentName == "")|(is.na(df$ParentName)),]

I recommend that you look at the dplyr package later, it will make data manipulation easier.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading