I have a huge dataset with over 2 million obs and 100 columns. There are 9 columns that contain ICD-10 disease codes that each of them start with a different letter.
For example:
icd1 <- c("O230", "B540", "D990", "Y555", "E980", "J777", "P090", "Q090", "R433")
icd2 <- c("O230", "B540", "D990", "Y555", "E980", "J777", "P090", "Q090", "Z433")
icd3 <- c("X230", "B540", "D990", "Y555", "E980", "J777", "P090", "Q090", "Z433")
data <- as.data.frame(rbind(icd1, icd2, icd3))
What I need to do is create a new column called "ICD_Z" that checks every one of those 9 ICD-10 columns codes to see if any of them starts with the letter Z, so if that's the case, the column I created would receive 1, or else, 0. But it only can receive 1 if all those 9 columns don't have an ICD-10 code that starts with the letter O.
So my output would look like this:
How can I do that?
