r - Two-way table with tables producing 1's -
i'm trying make simple two-way table tabluar()
, i'm getting 1's in output.
why estimates not showing , 1's instead?
sample code
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"))
make table
library(tables) tab1 <- latex(tabular(temp ~ crop*reg*(impact + se), data = pred.table))
output
\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 & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ \\ +2c & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ \\ +3c & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ \\ +4c & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ \\ +5c & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $1$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ & $0$ \\ \hline \end{tabular}
i think problem lies within part of code:
tabular(temp ~ crop*reg*(impact + se), data = pred.table)
if read documentation ?tabular
, you'll find passage:
if term evaluates function, should summary function produces scalar value when applied vector of values, , scalar displayed in table. example, (mean + var) ~ x display mean of x above variance of x. if no function specified, length assumed, table display counts. (at 1 summary function may specified in 1 term, mean*var error.)
you one-values because counts. want, should use similar line:
tabular(temp ~ crop * reg* (impact + se) * mean , data = pred.table)
i guess not entire solution bring closer. let me know in comments, if s.th. missing
Comments
Post a Comment