data.frame, cbind is inconsistent with S on logicals (PR#316)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Wed, 10 Nov 1999 12:59:43 +0100 (MET)


> From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
> Date: 10 Nov 1999 12:14:33 +0100
> 
> ripley@stats.ox.ac.uk writes:
> 
> > R 0.65.1 (and R-devel 09/11/99)
> > 
> > > z <- data.frame(a=1:3)
> > > b <- rep(NA, 3)
> > > mode(b)
> > [1] "logical"
> > # how many of you expected that? I had forgotten!
> > > zz <- cbind(z, b)
> > > zz
> >   a  b
> > 1 1 NA
> > 2 2 NA
> > 3 3 NA
> > > class(zz$b)
> > [1] "factor"
> > 
> > whereas in S it is NULL and zz$b is of mode "numeric".
> > 
> > The same thing happens with data.frame
> > 
> > zz <- data.frame(a, b)
> > 
> > gives zz$b as a factor in R and numeric in S.
> > 
> > I don't think this is a desirable difference, at least with all NAs!
> 
> Hmmm. Notice that in *both* R and S3,
> 
> > class(data.frame(x=TRUE)$x)
> [1] "factor"
> 
> And in both dialects, NA is a logical constant. So S3 is doing a
> special exception for all-NA logical vectors. Of course, we could just
> clone that...

It isn't: I was using the S4-style data frame code in my copy of
S-PLUS 3.4 (it is needed for some recent extensions) and had not
noticed.  And S4 keeps these logical, which seems much more desirable
to me.  In both R and S it is a quirk that

z$b <- b

and 

z <- cbind(z, b)

are different, but not in S4 nor in S3+library(df)

I withdraw this.

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