Adjust head and subtext with knitr/sweave

21 views
Skip to first unread message

rapp...@gmail.com

unread,
Aug 15, 2016, 5:05:04 AM8/15/16
to compareGroups Forum
I just discovered the wonderful package compareGroups and I think this may help me a lot in the future. So far, it is working brilliantly in combination with Knitr/Sweave:

\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!

compareGroups

unread,
Aug 16, 2016, 6:43:24 AM8/16/16
to compareGroups Forum
When exporting or printing the descriptive table using "print" function or "export2" functions like export2latex or export2md, make use of label argument 
Following your example,

<<results = "asis">>=

tab <- compareGroups(vs ~ . , data = mtcars)
export2latex(createTable(tab), header=c(p.overall='p-value'))

@

I hope this helps.

About adding an extra column with the t-test statistic or chi-squared values, etc., is not implemented yet. We will consider to add this possibility in future version of the compareGroups package.


Isaac.

Reply all
Reply to author
Forward
0 new messages