\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LaTeX packages needed for compareGroups
% long tables
\usepackage{longtable}
% multi row
\usepackage{multirow}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
% R code
<<results = "asis">>=
library(compareGroups)
# Very short code for bivariate descriptive table
tab <- compareGroups(vs ~ . , data = mtcars)
export2latex(createTable(tab))
@
\end{document}
I have only two concerns which is i) the modification of the table head (e.g. I want to print "P value" instead of "p.overall") and ii) adding a multicolumn subtext (e.g. "t-test was used to calculate P values."). If I just exported the table to LaTeX Code, it would be easy to modify head and subtext but in combination with Knitr I don't know how to deal with it. I just really would appreciate this wonderful solution over laborious functions in combination with e.g. Xtables package.
Thanks so much for your help!