如何让 xtable (尽管我也遇到 pander.table 的这个问题)将希腊字母分配给打印功能中的数据框的列,而无需渲染表格,然后手动输入 Latex 的希腊字母?
这是可重现示例的数据:
#data in
chiSq <- 1600
df <- 850
p <- 0.95
CFI <- 0.95
TLI <- 0.95
RMSEA <- 0.04
LOWRMSEA <- 0.03
HIGHRMSEA <- 0.04
我通常有一些看起来像这样的数据框。
fit.stat <- data.frame(chiSq, df, p, CFI, TLI, RMSEA, LOWRMSEA, HIGHRMSEA)
以下是我在使用 xtable 制作数据框表时经常遇到的一些具体问题:
- 我想做的是将 chiSq 更改为卡方的符号。在乳胶中,这
$x^2$
将呈现适当的符号。 - 我还需要 p 是斜体。
- 最后,LOWRMSEA 和 HIGHRMSEA 是上限和下限,我希望它们删除列名并将数据包含在 RMSEA 的列中,就像置信区间一样。
我发现这样做的唯一方法是先用这个命令打印表格
library(xtable)
print(xtable(fit.stat, caption = "Model Fit Information for CFA"),
caption.placement="top",
type = "latex")
产生这个:
\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}
但是,我需要手动编辑表来创建它:
\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}
我希望能够在不手动编辑表格的情况下动态地执行此操作,以便我可以将其作为代码块包含在降价文档中。谢谢。