[R] row.name in data.frame

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 5 22:25:02 CEST 2004


?read.table and the R Data Import/Export manual (and An Introduction to R)
do all explain this.

To use header=TRUE the header should not name the row names column, *OR* 
you need to add row.names=1 to the call.  So just omit `Species'.

On Tue, 5 Oct 2004, S Peri wrote:

> Hi Group, 
>  
>  I have a table with column names and row names. 
> 
> Species  A  B  C  D  E   F  G 
> Human    1  2  3  4  1   0  3
> Rat      0  2  3  3  2   1  2
> 
> 
> I read this tab delim. text file into R like the
> following:
> > mydata <-read.table('mydata.txt',header=TRUE)
> > mydata
>   Species A B C D
> 1   Human 1 2 3 2
> 2     Rat 0 2 5 2
> 3     Cat 9 2 4 1
> 
> 
> Why am I getting 1,2,3 row names even after declaring
> heder = TRUE.  I tried declaring row.names = NULL,
> however it is not accepting it and expects a vector
> with some names. I wanted Human, Rat and Cat as my row
> names. I wanted my data frame look like:
> 
> Species A B C D
> Human 1 2 3 2
> Rat 0 2 5 2
> Cat 9 2 4 1
> 
> I apologise for asking a lame question and this
> question might have been posted several times. I could
> not find an answer. 

Really?  Have you looked at the examples in `An Introduction to R'?

-- 
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