Skip to content

latex(test, collabel=) returns wrong latex code?

3 messages · Simon Kiss, Duncan Mackay, David Winsemius

#
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.
#
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:
#
On Mar 15, 2013, at 12:33 PM, Simon Kiss wrote:

            
(This is more of a comment than an answer. I am only able to achieve part of what I think was your goal.)

Since there is no argument to latex named 'collabel', I am guessing you may be getting partial name matching to `collabel.just`, and I doubt that 'Vote' is a valid argument for the Latex interpreter. `rowlabel` is supposed to be a column name in the 'object' argument. I'm not sure I can say what is supposed to happen when you give it a column name that is not in the object. I wasn't able to get the example in the help(latex) page to display rownames. I suspect you need to refer to the vignette:

http://biostat.mc.vanderbilt.edu/wiki/pub/Main/StatReport/summary.pdf 

.... and I think you need the argument rowname rather than rowlabel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: file6b77a205c01.pdf
Type: application/pdf
Size: 4323 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130316/6a69a742/attachment.pdf>
-------------- next part --------------