I am working with data where co-morbidities are coded for individuals in multiple columns and I want to create code that produces a binary column if it is present (1=disease present, 0=not present). For each individual they have multiple columns in which this could be in as well as the diagnoses being listed randomly and in no order. Also for each illness there may be multiple codes which equate to the same diagnosis.
For example, say there are two patients and each has 10 diagnosed diseases which are shown as columns, for example disease_1, disease_2, etc.. Disease X may be coded with I10 or B42. For the first individual I10 may be in the second column and for the second individual B42 may be in the seventh column. The result of the code would be that both individuals have a 1 in a newly created column.
I have tried using the mutate function of tidyverse and starts_with but am struggling to produce code. I have a rough mock-up of what I have tried but don't think I am particularly close. I would be grateful for any help.
Date_disease_column <- df %>%
startsWith(if_any(.cols = starts_with("disease"), "I10") ~ "1"))