I would like to transpose (i.e. vectors as columns) a data.frame in R and export it to Latex without row numbers but with a column instead. I would like to have an output like this:
But
df <- data.frame(qwertz=c("a","b","c","d","e","f"), asdfg=c("a","b"))
i.e.
qwertz asdfg
1 a a
2 b b
3 c a
4 d b
5 e a
6 f b
When I use xtable and booktabs
library(xtable)
print(xtable(t(df)), include.colnames=FALSE, booktabs=TRUE)
latex outpout is
i.e.
print(xtable(t(df)), include.colnames=FALSE, booktabs=TRUE)
% latex table generated in R 3.0.2 by xtable 1.7-1 package
\begin{table}[ht]
\centering
\begin{tabular}{rllllll}
\toprule
\midrule
qwertz & a & b & c & d & e & f \\
asdfg & a & b & a & b & a & b \\
\bottomrule
\end{tabular}
\end{table}
Question: how can I have directly the \midrule
between the two lines?
I tried with toLatex()
from ENmisc
and Latex()
from Hmisc
too and after reading these two questions:
xtable
output? – gung - Reinstate Monicaxtable
here – nebi