I'm pretty new to using R but I am currently working on an assignment where I was asked to create a descriptive table that can give a viewer a general idea of the data I am working with. I have been attempting to make something with gt_summary, but am running into countless hurdles and I can't get the output table to look how I want. At this point I basically have 3 gt tables that give me the count for each category (among sex, race, and age groups). When I try to combine them I get this horrible messy table with a ton of NA values. If anyone has any advice for how I could clean this up or if there are better ways to go about this problem I would really appreciate it. The output is in the picture I attached. Thanks in advance!
# Count occurrences for each racial group
racial_counts <- hais %>%
count(Q45) %>%
rename(Race = Q45, Count = n)
racial_counts
gt_race <- gt(racial_counts)
gt_race
# Count occurrences for each sex
sex_counts <- hais %>%
count(Q41) %>%
rename(Sex = Q41, Count = n)
sex_counts
gt_sex <- gt(sex_counts)
# Count occurrences for each age category
age_counts <- hais %>%
count(Q42) %>%
rename(Age = Q42, Count = n)
age_counts
gt_age <- gt(age_counts)
#combine counts
combined_counts <- bind_rows(sex_counts, age_counts, racial_counts)
#create new table and print
gt_combin <- gt(combined_counts)
gt_combin
Would you mind sharing your output and data with us? That way we can better help address your issue. Would you also mind sharing the gtsummary code you used? Perhaps someone can help troubleshoot there.
If I have understood your question then I think it is pretty straightforward to do with gtsummary:
This will give you two columns, one with the overall number of observations and a second with the breakdown into each category. The output should look like this: