[R] xtable without rownames
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat May 15 07:48:29 CEST 2004
rownames are for a matrix.
row.names are for a data frame.
I think you have confused your helpers. Try coercing to a matrix first.
I am not sure it will `work fine': it does still seem to have an empty
column for the row names. This is hard-coded in print.xtable in the lines
cols <- matrix("", nrow = nrow(x), ncol = ncol(x) + 1)
cols[, 1] <- row.names(x)
and since e.g. write.table has options to not include row and column
names, it would be nice if this could be added to xtable.
Also, this ought not to work. xtable.matrix makes use of
dimnames<-.data.frame which fails to check if the row names are duplicated
and so creates an invalid data frame. That is a bug, and it will be
fixed in due course.
On Fri, 14 May 2004, Jeff D. Hamann wrote:
> I just can't get it to work... I've got a data.frame that looks like,
>
> > ata
> age.class acres
> 1 0 94.25871
> 2 10 202.58106
> 3 20 254.74497
> 4 30 326.43598
> 5 40 170.75596
> 6 50 146.50230
> 7 60 76.84737
> 8 70 90.65786
> 9 80 44.59983
> 10 90 56.42965
> 11 100 34.48122
> 12 200 11.21226
> >
>
> and when I attempt to set the row names using,
>
> > rownames( ata ) <- rep( "", nrow(ata) )
>
> I cannot print out the data.frame as I get the error message,
>
> > rta
> Error in data.frame(site.index = c("80", "90", "100", "110", "120", "130",
> :
> duplicate row.names:
Where did `rta' and `site.index' come from?
> and setting the values to NULL, yields,
>
> > rownames( ata ) <- NULL
> Error in "dimnames<-.data.frame"(`*tmp*`, value = dn) :
> invalid dimnames given for data frame
> > rownames( ata ) <- rep( NULL, nrow(ata) )
> Error in "dimnames<-.data.frame"(`*tmp*`, value = dn) :
> invalid dimnames given for data frame
> >
>
> So just how do I do it?
>
> ----- Original Message -----
> From: <Brian.J.GREGOR at odot.state.or.us>
> To: <jeff.hamann at forestinformatics.com>; <r-help at stat.math.ethz.ch>
> Sent: Thursday, May 13, 2004 9:13 AM
> Subject: RE: [R] xtable without rownames
>
>
> > You can just set the rownames to an empty character string ("") and xtable
> > will work fine.
> >
> > > -----Original Message-----
> > > From: Jeff D. Hamann [mailto:jeff.hamann at forestinformatics.com]
> > > Sent: Wednesday, May 12, 2004 5:40 PM
> > > To: r-help at stat.math.ethz.ch
> > > Subject: [R] xtable without rownames
> > >
> > >
> > > When I tried to read all the entries (after searching the
> > > FAQ) for "row
> > > names xtable", I get
> > >
> > >
> > > START-INFO-DIR-ENTRY * R FAQ: (R-FAQ). The R statistical system ...
> > > ... xtable* Export data to LaTeX and HTML tables. ... For
> > > dropping the row
> > > names of a matrix
> > > `x', it may be easier to use `rownames(x) <- NULL', similarly
> > > for column ...
> > > cvs.r-project.org/cgi-bin/viewcvs.cgi/R/FAQ?rev=1.301 - 101k
> > > - Supplemental
> > > Result - Cached - Similar pages
> > > I wasn't able to follow the link. I'd like to use xtable to
> > > generate latex
> > > tables for using with Sweave and can't figure out how to not
> > > include the row
> > > names. When I attempt to NULL out the row names using,
> > >
> > > but cannot follow the links. Browser tells me the page is
> > > unavailable. When
> > > I attempt to blank out the row names using,
> > >
> > > rownames(summary.table) <- NULL
> > >
> > > I get the following error
> > >
> > > > rownames(rta) <- NULL
> > > Error in "dimnames<-.data.frame"(`*tmp*`, value = dn) :
> > > invalid dimnames given for data frame
> > > >
> > >
> > > the resulting (incorrect) table appears as,
> > >
> > > > xtable( rta )
> > > % latex table generated in R 1.9.0 by xtable 1.2-2 package
> > > % Wed May 12 17:38:21 2004
> > > \begin{table}[ht]
> > > \begin{center}
> > > \begin{tabular}{rlr}
> > > \hline
> > > & site.index & acres \\
> > > \hline
> > > 1 & 80 & 20.90 \\
> > > 2 & 90 & 64.42 \\
> > > ...blah, blah, blah...
> > > 8 & 150 & 53.32 \\
> > > 9 & 170 & 0.69 \\
> > > \hline
> > > \end{tabular}
> > > \end{center}
> > > \end{table}
> > > >
> > >
> > > with the rownames. How do I get them out?
> > >
> > > I'm stuck. Help.
> > >
> > > Jeff.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list