双向 table,table 生成 1

Two-way table with tables producing 1's

我正在尝试用 tabluar() 制作一个简单的双向 table,但我得到的只是输出中的 1。

为什么我的估算值没有显示,而我得到的是 1?

示例代码

pred.table <- structure(list(temp = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 
5L, 1L, 2L, 3L, 4L, 5L), .Label = c("+1C", "+2C", "+3C", "+4C", 
"+5C"), class = "factor"), crop = structure(c(1L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L), .Label = c("A", "B", "C", 
"D", "E"), class = "factor"), reg = structure(c(1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("CS", "DD", "P"
), class = "factor"), impact = c(-4.5, -11.15, -19.62, -29.37, 
-39.8, -7.22, -19.77, -35.53, -51.96, -66.89, 0.47, -0.42, -2.79, 
-6.66, -11.96, -9.02, -19.94, -32.06, -44.58, -56.66, -5.11, 
-12.97, -23.04, -34.53, -46.57, 0.24, 0.28, 0.06, -0.45, -1.27, 
-12.11, -24.4, -37.07, -49.95, -62.45, -11.67, -23.86, -36.03, 
-47.69, -58.41, -4.15, -9.14, -14.91, -21.34, -28.29), se = c(2.39, 
2.41, 2.44, 2.47, 2.5, 4.18, 4.11, 4.01, 3.91, 3.78, 2.13, 2.13, 
2.14, 2.15, 2.16, 0.6, 0.62, 0.65, 0.69, 0.74, 0.82, 0.82, 0.83, 
0.83, 0.83, 0.47, 0.48, 0.5, 0.51, 0.53, 2.47, 2.5, 2.55, 2.62, 
2.72, 14.88, 14.96, 15.08, 15.23, 15.42, 8.3, 8.39, 8.49, 8.6, 
8.74)), class = "data.frame", row.names = c(NA, -45L), .Names = c("temp", 
"crop", "reg", "impact", "se"))

制作Table

library(tables)
tab1 <- latex(tabular(temp ~ crop*reg*(impact + se), data = pred.table))

输出

\begin{tabular}{lcccccccccccccccccccccccccccccc}
\hline
 & \multicolumn{30}{c}{crop} \ 
 & \multicolumn{6}{c}{A} & \multicolumn{6}{c}{B} & \multicolumn{6}{c}{C} & \multicolumn{6}{c}{D} & \multicolumn{6}{c}{E} \ 
 & \multicolumn{6}{c}{reg} & \multicolumn{6}{c}{reg} & \multicolumn{6}{c}{reg} & \multicolumn{6}{c}{reg} & \multicolumn{6}{c}{reg} \ 
 & \multicolumn{2}{c}{CS} & \multicolumn{2}{c}{DD} & \multicolumn{2}{c}{P} & \multicolumn{2}{c}{CS} & \multicolumn{2}{c}{DD} & \multicolumn{2}{c}{P} & \multicolumn{2}{c}{CS} & \multicolumn{2}{c}{DD} & \multicolumn{2}{c}{P} & \multicolumn{2}{c}{CS} & \multicolumn{2}{c}{DD} & \multicolumn{2}{c}{P} & \multicolumn{2}{c}{CS} & \multicolumn{2}{c}{DD} & \multicolumn{2}{c}{P} \ 
temp  & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & se & impact & \multicolumn{1}{c}{se} \ 
\hline
+1C  & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ \
+2C  & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ \
+3C  & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ \
+4C  & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ \
+5C  & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & $ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ & [=13=]$ \
\hline 
\end{tabular}

我认为您的问题出在这部分代码中:

tabular(temp ~ crop*reg*(impact + se), data = pred.table)

如果您阅读 ?tabular 的文档,您会发现该段落:

If the term evaluates to a function, it should be a summary function that produces a scalar value when applied to a vector of values, and that scalar will be displayed in the table. For example, (mean + var) ~ x will display the mean of x above the variance of x. If no function is specified, length is assumed, so the table will display counts. (At most one summary function may be specified in any one term, so mean*var would be an error.)

你得到一个值是因为你得到了计数。要得到你想要的,你应该使用类似于这一行的东西:

tabular(temp ~ crop * reg* (impact + se) *   mean , data = pred.table)

我想这不是完整的解决方案,但可以让您更接近。如果 s.th,请在评论中告诉我。不见了