I have this data:
structure(list(id = 1:6, arthritis = c(1L, 0L, 0L, 0L, 0L, 1L
), asthma = c(0L, 0L, 0L, 0L, 0L, 0L), cancer = c(0L, 0L, 0L,
0L, 0L, 0L), cerebvascdz = c(0L, 0L, 0L, 0L, 0L, 0L), chf = c(0L,
0L, 0L, 0L, 0L, 0L), crf = c(0L, 0L, 0L, 0L, 0L, 0L), copd = c(0L,
0L, 0L, 0L, 0L, 0L), depression = c(0L, 0L, 0L, 1L, 1L, 1L),
diabetes = c(0L, 0L, 0L, 0L, 0L, 0L), hyperlipid = c(1L,
0L, 1L, 0L, 1L, 0L), htn = c(1L, 0L, 1L, 1L, 0L, 1L), ihd = c(1L,
0L, 0L, 0L, 0L, 0L), obesity = c(0L, 0L, 0L, 0L, 0L, 0L),
osteoporosis = c(0L, 0L, 0L, 0L, 0L, 1L)), row.names = c(NA,
6L), class = "data.frame")
which contains an id for a patient. all the rest of the columns are comorbidities that the patient might have, designated as a boolean. I'm trying to use the gather method to flip the table around, as shown like this. Every comorbidity that the patient has is supposed to be populated on the right with the patient id on the left.
I'm pretty sure I'm supposed to be using the gather function, but I can't seem to get this working. Does anyone have any insight into what I should be doing to have the frame switch to the required format?