[R] why does data frame subset return vector

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Oct 18 14:47:01 CEST 2003


Do look at the discussion of the drop argument in ?"[.data.frame".
It is all in TFM, and there is nothing `wiered' about it.

On Sat, 18 Oct 2003 Arne.Muller at aventis.com wrote:

> I've a weired problem with a data frame. Basically it should be just one
> column with
> specific names coming from a data file (the file contains 2 rows, one should
> be
> the for the rownames of the data frame the other contains numeric values).
> 
> > df.rr <- read.table("RR_anova.txt", header=T, comment.char="", row.names=1)
> > df.rr[c(1,2,3),]
> [1] 1.11e-16 1.11e-16 1.11e-16
> 
> Why are the rownames not displayed?

Because data frames have row names (with a space) and vectors do not.

[...]

> Any explanation is appreciated. There must be a good reason for this I guess
> ... . On
> the other hand is there a way to fore the subset of the 1 colum data frame to
> be
> dataframe itself? I'd just like to see the rownames displayed, that's it ...

The help page will tell you how.

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