[Rd] factors in data.frames (PR#835)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Thu, 1 Feb 2001 11:15:26 +0100 (MET)


> From: james.lindsey@luc.ac.be
> Date: Thu, 1 Feb 2001 10:56:07 +0100 (MET)
> 
> The following seems to be a contradiction:

What is, pray?

> class(df[, 1])
[1] "factor"
> class(df[, 1, drop = FALSE])
[1] "data.frame"

df[ , 1, drop=FALSE] is a data frame, so not a factor.
df[ , 1] is a factor.

> > df <- data.frame(x=gl(2,1,10))
> > df[,1]
>  [1] 1 2 1 2 1 2 1 2 1 2
> Levels:  1 2 
> > df[,1,drop=F]
>    x
> 1  1
> 2  2
> 3  1
> 4  2
> 5  1
> 6  2
> 7  1
> 8  2
> 9  1
> 10 2
> > is.factor(df[,1,drop=F])
> [1] FALSE
> > is.factor(df[,1])
> [1] TRUE
> 
> with R1.2.1 both MS Windows and Intel RH5.2 versions.
>  Jim

-- 
Brian D. Ripley,                  ripley@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-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._