How to filter new group by NOT HAVING certain characteristics

Hi, I have a large dataset "Procedure" with a category "Airway and Respiratory" with different types of ventilatory supports that patients have received in the hospital. I want to categorize patients into 3 groups based on different airway and resp managements--1) Non-invasive respiratory procedures (as defined by filtered resp procedures "bipap", "cpap", etc), 2) Invasive respiratory procedures (as defined by filter "endotracheal intubations"), and finally 3) No respiratory procedures (patients who neither received non-invasive or invasive).

I cannot figure out how to filter the last group (no resp procedure). Patients in my dataset have received multiple resp procedures, which include other things outside of non-invasive/invasive, so I cannot just filter out by "null". I just don't know how to filter those patients who DID NOT received intubations / bipap/cpap etc. I was thinking I could use ifelse, but cannot figure out a clean way to do this. Please help!

#StartRcode
Proc <- read.csv("Procedure.csv", stringsAsFactors = F)
Proc <- tbl_df(Proc)

#Cleaning data
RespProc <- filter(Proc, Category == "Airway and Respiratory")
NIRespProc <- filter(RespProc, Procedure.Name == "BiPAP" | Procedure.Name == "BiPAP (non-invasive)" | Procedure.Name == "CPAP (Non-Invasive)" | Procedure.Name == "CPAP")
InvRespProc<- filter(RespProc, Procedure.Name == "Endotracheal Intubation(and duration of intubation)")
NoRespSupport <- filter(RespProc, Procedure.Name==)

You should have a look at %in% as it should make your code cleaner.

NI_treatments <- c("BiPAP", "BiPAP (non-invasive)", "CPAP (Non-Invasive)", "CPAP") NIRespProc <- filter(RespProc, Procedure.Name %in% NI_treatments)

To get those that didn't get support you can negate the condition

NIRespProc <- filter(RespProc, !Procedure.Name %in% c(NI_treatments, I_treatments))

Yes!! Thank you so much--this is exactly what I was looking for! This is going to make my project that much easier.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.