[R] Removing "row.names"

Patrick Connolly P.Connolly at hortresearch.co.nz
Wed Feb 7 03:07:32 CET 2001


According to Kurt Hornik:
|> 
|> >>>>> 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.

Interestingly, it IS possible to do it in Splus by converting your
dataframe to a matrix, changing the rownames of it to be a vector of
empty strings then converting it back to a data frame.  It seems as
though the normal checking doesn't happen and it's possible to do what
Marc wanted to do.  Character columns will mean that your resulting
dataframe will be all character columns, so it's likely more tinkering
is necessary.

I tried the same technique in R but it insisted on renumbering the
rows of the dataframe with the added bonus of making each column into
a factor.  

As if that is not strange enough, simply listing without assignment of
the as.data.frame(fudge.matrix) will return an error, complaining
about non-unique row names, but it will create another object without
much fuss.

The dataframe I used for my test had one factor column and 5 numeric
columns.  Things might be different again with other data.

best

-- 
*************************************************************
Patrick Connolly
HortResearch        
Mt Albert               It's better to do nothing than to waste time
Auckland                                      ..... Viktoras Kulvinskas
New Zealand                          
Ph: +64-9 815 4200 x 7188
*************************************************************
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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