Help with organizing data by unique identifier

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))

The current layout is not tidy, because no column has rows with unique values (in SQL terms, there is not key field).

Consider a tidyr pivot operation so that new columns for each procedure name are created; then creating a classification of CaseIndexID reflecting combinations of procedures will be straightforward.

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.