I am trying to create a summary table for data where participants have been asked to indicate their opinion on a variety of items on a 5 point likert scale. (code to generate sample data at the end). I want to show the frequency of responses for each item and the proportion as a percentage. I would also ideally like to show the average response for each item.
It should look something like this (dummy data, not accurate):
item | strongly oppose | somewhat oppose | neutral | somewhat support | strongly support | Average |
---|---|---|---|---|---|---|
1 | 2 (1%) | 8 (1%) | 81(11%) | 277 (37%) | 377(51%) | neutral |
2 | 4 (2%)… |
I am currently using the following code to do this:
df %>% select(c(Q1:Q17)) %>% tbl_summary(
)%>%
modify_header(label ~ "")%>%
modify_spanning_header(c("label") ~ "**Support for Items**")%>%
as_gt()
Which works but generates separate summary tables for each of the items, I want to create one table with a column for option and a row for each item as in the example. Any advice would be appreciated.
Code to generate data:
df1 <- data.frame(ID = c(1, 2, 3, 4, 5),
item1 = c('strongly support', 'neutral', 'oppose', 'somewhat oppose', 'somewhat support'),
item2 = c('oppose', 'strongly support','somewhat support', 'strongly oppose', 'neutral'),
item3 = c('oppose','oppose','oppose','strongly support','somewhat support'),
item4 = c('oppose','strongly support','oppose','strongly support','somewhat support'),
item5 = c('oppose','strongly oppose','oppose','strongly support','somewhat support'))