library(tables)
iris2 <- iris[ iris$Species != 'versicolor', ]
iris2$Species <- factor(iris2$Species)
tmp <- tabular( Petal.Width+Petal.Length + Sepal.Width+Sepal.Length ~ Species* (mean+sd), data=iris2 )
tmp.p <- sapply( names(iris2)[1:4], function(x) t.test( iris2[[x]] ~ iris2$Species )$p.value )
tmp
> tmp
Species
setosa virginica
mean sd mean sd
Petal.Width 0.246 0.1054 2.026 0.2747
Petal.Length 1.462 0.1737 5.552 0.5519
Sepal.Width 3.428 0.3791 2.974 0.3225
Sepal.Length 5.006 0.3525 6.588 0.6359
I want to turn my R table into latex code. So I ran
> latex(tmp, file = "")
% latex.default(tmp, file = "")
%
\begin{table}[!tbp]
\begin{center}
\begin{tabular}{rrrrrrrrrrrrrrrr}\hline\hline
\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}\tabularnewline\hline
$0.246$&$1.462$&$3.428$&$5.006$&$0.105385589380046$&$0.173663996480184$&$0.379064369096289$&$0.352489687213451$&$2.026$&$5.552$&$2.974$&$6.588$&$0.274650055636667$&$0.551894695663983$&$0.322496638172637$&$0.635879593274432$\tabularnewline
\hline
\end{tabular}
\end{center}
\end{table}
This is what R gave me. But the problem is there is only 1 row, when there should actually be at least 5. First row is for the species names, second is petal width, third is petal length, and so on. Does this have to do with tmp
being class tabular
and not table
? What can I change so that the table looks right in latex format? Also, is there a way of writing mean (sd)
in just one column for setosa's petal width, i.e., 0.246 (0.105)
, instead of having two separate columns?