I am trying to use R markdown to create a report that contains 3-way contingency tables. I am able to create the tables quite easily using ftable(), but they are not formatted well for printing in markdown.
The output has to be a DOCX document. Therefore, anything that is designed to format for HTML or LaTeX will not be useful to me.
The kable() function in knitr does not work with ftables, and many other options will simply print it as a data frame. When converting an ftable to a data frame, it messes up how it is laid out, so those are not helpful, either.
I created a reproducible example of a 3-way table created using ftable that should be roughly the size of the tables I need to output:
library(tidyverse)
# this data set is included in dplyr
data("starwars")
data=starwars
#the next couple of lines are just me trimming down the information to be used in the table
data=data %>% filter(species=="Human" | species=="Droid" | species=="Zabrak" | species=="Mirialan" | species=="Wookiee")
tabledata=data[,c(8:10)]
#here's the actual table
table1 = ftable(tabledata,col.vars=c(3,1))
table1
I'm hoping for a fairly simple solution, if possible (maybe a package that does it for me, or something). This report will contain many tables, and so doing something too complex will take too long (also, I've only begun using R recently).
Thanks in advance for any help y'all can provide!