How do I get xtable (though I also have this issue with pander.table) to assign Greek letters to columns of a data frame within the print function without me needing to render the table and then manually type in the Latex for the Greek letters?
Here's the data for a reproducible example:
#data in
chiSq <- 1600
df <- 850
p <- 0.95
CFI <- 0.95
TLI <- 0.95
RMSEA <- 0.04
LOWRMSEA <- 0.03
HIGHRMSEA <- 0.04
I typically have some data frame that looks like this.
fit.stat <- data.frame(chiSq, df, p, CFI, TLI, RMSEA, LOWRMSEA, HIGHRMSEA)
Here are some specific issues that I regularly encounter when I go to make a table of data frame with xtable:
- What I would like to do is to change the chiSq to the symbol for chi-square. In latex this
$x^2$
will render the appropriate symbol. - I also need the p to be in italics.
- Finally, the LOWRMSEA and HIGHRMSEA are upper and lower bounds, and I'd like them to remove the column names and include the data in the column for RMSEA, in the same way you would confidence intervals.
The only way I have found to do this is to print the table first with this command
library(xtable)
print(xtable(fit.stat, caption = "Model Fit Information for CFA"),
caption.placement="top",
type = "latex")
Which produces this:
\begin{table}[ht]
\centering
\caption{Model Fit Information for CFA}
\begin{tabular}{rrrrrrrrr}
\hline
& chiSq & df & p & CFI & TLI & RMSEA & LOWRMSEA & HIGHRMSEA \\
\hline
1 & 1600.00 & 850.00 & 0.95 & 0.95 & 0.95 & 0.04 & 0.03 & 0.04 \\
\hline
\end{tabular}
\end{table}
However, I then need to manually edit the table to create this:
\begin{table}[ht]
\centering
\caption{Model Fit Information for CFA}
\begin{tabular}{rrrrrrrrrrrr}
\hline
& $x^2$ & {\it df} & {\it p} & CFI & TLI & RMSEA\\
\hline
&1600.00 & 850.00 & 0.00 & 0.95 & 0.95 & 0.04 (0.03 - 0.04) \\
\hline
\end{tabular}
\end{table}
I'd like to be able to do this dynamically without manually editing the tables so that I can include it as a code chunk in markdown doc. Thanks.