[R] Summary: Removing "row.names"

Marc Feldesman feldesmanm at pdx.edu
Wed Feb 7 22:08:29 CET 2001

Thanks to all who offered suggestions for my question of how to "remove" 
row.names.  As Bill Venables patiently pointed out, row.names are part of 
the object-oriented design of the S language (all dialects).  As a result, 
there is no way to "literally" remove row.names and still have a 
data.frame.  This was a useful thing to have Bill point out.  In fact, my 
problem was not really one of removing row.names, but changing row names to 
the default, as Brian Ripley correctly deduced from my message.

The problem arose when I received a large (ca 28,000 row) data file in 
simple .csv format.  The first row of the data set had variable names - 
"ID", followed by the names of about 10 other variables.  The following ca. 
27999 rows contained the data - one row per case.  I read the data into R 
as follows:

monkeys<-read.table("monkey.txt", header=TRUE, sep=",")

The process occurred without incident until I actually looked at the data 
brought into R.  I had expected that the ID variable would come across as a 
simple character variable labelled "ID".  It didn't.  Because the ID was 
unique, R apparently took it to be the row.name, rather than defaulting to 
the "normal".   I wasn't expecting this to occur, and the help for 
read.table() didn't suggest to me that it would occur.   All I was trying 
to do, in effect, was to eliminate the ID variable as the row.name and 
replace it by the default.  I didn't explain this very well.  My approach 
accomplished what I intended to do.  Several suggested other approaches 
that would have achieved the same effect.

After looking really closely at the original data file, I can see quite 
clearly the its author omitted one of the variable names and so there were 
fewer variable names than there were columns.  When I added the missing 
variable name, R correctly read the file in as I had expected it would.

I don't know if this is a bug in R (i.e. is R supposed to default to using 
column 1 as row.names if there are fewer column names than columns *and* 
column 1 is unique), or if it is working as designed.

Dr. Marc R. Feldesman
Professor and Chairman
Anthropology Department
Portland State University
1721 SW Broadway
Portland, Oregon 97201
email:  feldesmanm at pdx.edu
phone:  503-725-3081
fax:    503-725-3905
PGP Key Available On Request

"Anyway, no drug, not even alcohol, causes the fundamental ills of society.
If we're looking for the source of our troubles, we shouldn't test people
for drugs, we should test them for stupidity, ignorance, greed and love of
power."   P.J. O'Rourke

Powered by Optiplochoerus and Windows 2000 (scary isn't it?)

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