Linelists usually have symptoms reported.
People usually experience 1 or more symptoms.
This is a bit of a formatting issue.
I want the symptoms to be displayed like the single categories are displayed normally. For example:
I have demo data:
set.seed(123)
symptoms <- c( "fever", "cough", "shortness_of_breath", "fatigue", "headache", "sore_throat")
df <- data.frame(
fever = rbinom(n, 1, 0.5),
cough = rbinom(n, 1, 0.5),
shortness_of_breath = rbinom(n, 1, 0.5),
fatigue = rbinom(n, 1, 0.5),
headache = rbinom(n, 1, 0.5),
sore_throat = rbinom(n, 1, 0.5),
ill = rbinom(n, 1, 0.5),
symptoms = apply(df[,2:7], 1, function(x) paste(symptoms[x == 1], collapse = ", ")),
any_symptoms = apply(df[,2:7], 1, function(x) any(x == 1)),
age = rnorm(n, 50, 10)
)
This is my best attempt which is close, seemingly just needing some bolding and and padding:
syms_table<- df%>%
select(all_of(symptoms))%>%
tbl_summary()
age_table <- df %>%
select(age)%>%
tbl_summary()
final_table<- tbl_stack(list(syms_table, age_table), group_header = c("Symptoms", ""))
final_table
But, I usually also end up converting to flextable to produce word documents so I can get comments from supervisors and colleagues.
final_table%>%as_flex_table() %>%save_as_docx(., path = "symptoms.docx")
But this takes me a step back unfortunately:
[![a gtsummary objecte converted a to a flextable takes me a step back][3]][3]
I believe there could some of other long path of getting this right using a mix of gtsummary and flextable functions. But I would also like to believe that there is a “quick” way. Any help appreciated.