I am running frequencies for a peer-reviewed research paper and need to combine output into a table. An example of the format can be found here under "Results".
Essentially, it follows a style of heading/variable, with categories indented below, and n(%), either in one column or two.
I've tried to figure out a way to combine summarytools::freq()
and knittr::kable()
to get tables styled this way. One thing that I've tried is combining multiple freq() %>% as.data.frame()
statements with bind_rows()
. But that output is not very pretty.
I'm trying to avoid having to do a lot of cutting and pasting in Word because there were be a lot of tables, and I would like to get as close as possible to the desired format in my output. Any pointers?
Thank you!
The example you refer to uses cross-tabulation (joint frequencies for two categorical variables). So
summarytools::freq()
is probably not what you're looking for here, even though technically it can work if you use it withstby()
.summarytools::ctable()
would bring you a step closer, but there are other packages that might be better suited for this purpose, I'm thinking maybe tableone.