I'm printing frequency tables using knit::kable
and pander::pandoc
, and generally this works great for HTML/Word/LaTeX output. But sometimes I'd like to preserve dimension names in the final product. Unfortunately, both pander
and knitr
drop these when converting to markdown.
# create a simple table
tab <- table(mtcars$gear, mtcars$carb)
# add dimension names
names(dimnames(tab)) <- c("gear", "carb")
This creates a table:
carb
gear 1 2 3 4 6 8
3 3 4 3 5 0 0
4 4 4 0 4 0 0
5 0 2 0 1 1 1
But now if we print with, say, kable:
> kable(tab)
| | 1| 2| 3| 4| 6| 8|
|:--|--:|--:|--:|--:|--:|--:|
|3 | 3| 4| 3| 5| 0| 0|
|4 | 4| 4| 0| 4| 0| 0|
|5 | 0| 2| 0| 1| 1| 1|
No dimension names! (And ?kable
does not indicate any option that would include them.)
Any suggestions for a tool that will preserve these? I've noticed that descr:CrossTable
does the trick, but includes a whole lot of extra info I'd like to omit.
Many thanks.