【发布时间】:2021-07-03 04:03:23
【问题描述】:
我有一个数据框。例如,它看起来像这样:
Condition dv1_mean dv2_mean
A 1 2
A 2 3
A 2 3
B 3 4
B 3 4
B 3 4
C 3 4
C 3 4
C 3 4
我的代码如下:
stderr <- function(x) sd(x)/sqrt(length(x))
table<-toLatex(
tabular( (Condition + 1) ~ (n=1) + Format(digits=2)*
(dv1_mean + dv2_mean)*(mean + sd+median+stderr), data=accuracy ))
table
当我点击 knit PDF 时,我的代码的输出是一堆未格式化的混乱代码,如下所示:
\begin{tabular}{lccccccccc}
\hline
& & \multicolumn{4}{c}{dv1_mean} & \multicolumn{4}{c}{dv2_mean} \\
Condition & n & mean & sd & median & stderr & mean & sd & median & \multicolumn{1}{c}{stderr} \\
\hline
C1: Control & $\phantom{0}433$ & $\phantom{-}0.015$ & $\phantom{-}0.487$ & $-0.172$ & $\phantom{-}0.023$ & $\phantom{-}0.022$ & $\phantom{-}0.595$ & $-0.199$ & $\phantom{-}0.029$ \\
C2: Brier-Continuous & $\phantom{0}423$ & $-0.063$ & $\phantom{-}0.452$ & $-0.243$ & $\phantom{-}0.022$ & $-0.142$ & $\phantom{-}0.532$ & $-0.339$ & $\phantom{-}0.026$ \\
C3: Superforecaster & $\phantom{00}17$ & $-0.306$ & $\phantom{-}0.129$ & $-0.309$ & $\phantom{-}0.031$ & $-0.266$ & $\phantom{-}0.346$ & $-0.354$ & $\phantom{-}0.084$ \\
C4: Reciprocal-Continuous & $\phantom{0}428$ & $-0.031$ & $\phantom{-}0.484$ & $-0.234$ & $\phantom{-}0.023$ & $-0.062$ & $\phantom{-}0.582$ & $-0.287$ & $\phantom{-}0.028$ \\
All & $1301$ & $-0.030$ & $\phantom{-}0.474$ & $-0.215$ & $\phantom{-}0.013$ & $-0.063$ & $\phantom{-}0.572$ & $-0.280$ & $\phantom{-}0.016$ \\
\hline
\end{tabular}
如何正确使用tables包和toLatex函数?
【问题讨论】:
标签: r datatables latex output pdflatex