[R] Removing "row.names"

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed Feb 7 08:12:20 CET 2001

On Tue, 6 Feb 2001, Kurt Hornik wrote:

> >>>>> Marc Feldesman writes:
> > I need to completely remove row.names from a dataframe.  Are there other
> > ways to remove them (and not anything else) besides:
> > mydataframe<-data.frame(mydataframe, row.names=NULL)
> > I realize that this doesn't really remove the row.names; it merely
> > replaces the current row.names vector with the numbers 1..nrow (in
> > quotes).
> My understanding is that you cannot do that.  By definition, data frames
> are lists all components of which have the same length, and have both
> names and row.names attributes which must have the right length and no
> duplicated elements.

I read it that Marc is happy with that, just wants to set the row names to
the default. The simplest way to do that is

row.names(mydataframe)  <- seq(len=nrow(mydataframe))

In S there are examples where in manipulating data frames, the manipulation
of the row names takes up most of the time (as they have to be kept
unique).  I believe one is in bootstrapping, and as a result the latest
versions of S-PLUS allow duplicate row names in data frames.  I suspect
something similar migth apply to R, but re-defining a class after
several years in use is not I think a good idea.

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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list