I'm trying to get a pdf with the results of the table command applied to two vectors.
For this I use knitr and the xtable package, although other solutions and advice are welcome, such as with Kable.
As an example we can create the table from this data.
table (c (2,5,5,5,5,7,7,7,7, NA), c (1,5,2,2,2,2,7,7, NA, NA) )
And I would like something like this:
As you can see the title of the left margin, var1 is rotated 90º.
How can I get that result or something similar?
I have tried several methods, as I show in the attached code, included in an Rnw file.
\documentclass{article}
\usepackage{booktabs}
\usepackage{rotating}
\begin{document}
<<r table, results='asis', echo=FALSE>>=
library(knitr)
library(xtable)
var1 <- c(2,5,5,5,5,7,7,7,7,NA)
var2 <- c(1,5,2,2,2,2,7,7,NA,NA)
print(xtable(table(var1,var2)))
print.xtableFtable(xtableFtable(ftable(var1,var2),
method = "row.compact"))
print.xtableFtable(xtableFtable(ftable(var1,var2),
method = "row.compact"), rotate.rownames = TRUE)
print.xtable(xtable(table(var1,var2)), include.rownames=T,include.colnames=T)
@
\end{document}
And the result obtained is shown in the following three tables.
But as you can see it does not look like what I'm looking for, I can not turn only var1.