[R] latex(test, collabel=) returns wrong latex code?
Duncan Mackay
mackay at northnet.com.au
Fri Mar 15 23:36:34 CET 2013
Hi Simon
the equivalent in xtable is
library(xtable)
xtable(test)
% latex table generated in R 2.15.2 by xtable 1.7-0 package
% Sat Mar 16 08:14:01 2013
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrr}
\hline
& A & B \\
\hline
A & 50.00 & 50.00 \\
B & 50.00 & 50.00 \\
\hline
\end{tabular}
\end{center}
\end{table}
I am wondering if the class is making things hard
test
A B
A 50 50
B 50 50
# as a data.frame
data.frame(test)
Var1 Var2 Freq
1 A A 50
2 B A 50
3 A B 50
4 B B 50
# Add column names
dimnames(test) <- list(c("Gender A", "Gender B"), c("Vote A", "Vote B"))
> test
Vote A Vote B
Gender A 50 50
Gender B 50 50
xtable(test)
xtable(test)
% latex table generated in R 2.15.2 by xtable 1.7-0 package
% Sat Mar 16 08:34:34 2013
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrr}
\hline
& Vote A & Vote B \\
\hline
Gender A & 50.00 & 50.00 \\
Gender B & 50.00 & 50.00 \\
\hline
\end{tabular}
\end{center}
\end{table}
I suppose a similar thing will happen with latex saves detaching
latex is a bit different in that it gives you multicolumn for the
header columns which can be modified (I have not used latex) for justification
I think the problem is in the arrangement of the data or the names
that you are sending to latex() someone else may have a different opinion
HTH
Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au
At 05:33 16/03/2013, you wrote:
>Hello:
>I'm working with a 2-dimensional table that looks sort of like test below.
>I'm trying to produce latex code that will add dimension names for
>both the rows and the columns.
>In using the following code, latex chokes when I include
>collabel='Vote' but it's fine without it.
>
>The code below prouces the latex code further below. I'm confused
>by this, because it looks like it's creating two bits of text for
>each instance of \multicolumn. Is that really allowed in \multicolumn?
>Could someone clarify?
>Thank you!
>Yours, SJK
>
>
>library(Hmisc)
>test<-as.table(matrix(c(50,50,50,50), ncol=2))
>latex(test, rowlabel='Gender',collabel='Vote', file='')
>
>% latex.default(test, rowlabel = "Gender", collabel = "vote", file = "")
>%
>\begin{table}[!tbp]
>\begin{center}
>\begin{tabular}{lrr}
>\hline\hline
>\multicolumn{1}{l}{Gender}&\multicolumn{1}{vote}{A}&\multicolumn{1}{l}{B}\tabularnewline
>\hline
>A&$50$&$50$\tabularnewline
>B&$50$&$50$\tabularnewline
>\hline
>\end{tabular}
>\end{center}
>\end{table}
>*********************************
>Simon J. Kiss, PhD
>Assistant Professor, Wilfrid Laurier University
>73 George Street
>Brantford, Ontario, Canada
>N3T 2C9
>Cell: +1 905 746 7606
>
>Please avoid sending me Word, PowerPoint or Excel attachments.
>Sending these documents puts pressure on many people to use
>Microsoft software and helps to deny them any other choice. In
>effect, you become a buttress of the Microsoft monopoly.
>
>To convert to plain text choose Text Only or Text Document as the
>Save As Type. Your computer may also have a program to convert to
>PDF format. Select File, then Print. Scroll through available
>printers and select the PDF converter. Click on the Print button and
>enter a name for the PDF file when requested.
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list