I have a data set "Procedure" that lists patients by a unique identifier and every respiratory procedure that they receive during an admission (example table below). I have a code that separates the procedures by 1) "Invasive (intubation)", 2) "Non-Invasive (NI)", and 3) "Other" respiratory procedures when a patient does not receive invasive or NI procedures. However, I want to count "other" resp procedures by unique patient identifier, and I do not think my code takes that into account. For example, in the example below, I would like patient "A1" to count as "non-invasive", patient B1 to count as "other" procedure, patient C1 to count as "non-invasive" AND "invasive" but NOT "other" procedure even though they received "humidified high flow oxygen" which counts as other. Please help!
RespProc <- filter(Proc, Category == "Airway and Respiratory")
Invasive_RespPro <- c("Endotracheal Intubation(and duration of intubation)")
Invasive_tx <- filter(RespProc, Procedure.Name %in% Invasive_RespPro)
NI_RespPro <- c("BiPAP", "BiPAP (non-invasive)", "CPAP", "CPAP (Non-Invasive")
NI_tx <- filter(RespProc, Procedure.Name %in% NI_RespPro)
Other_tx <- filter(RespProc, !Procedure.Name %in% c(NI_RespPro, Invasive_RespPro))