data.frame, cbind is inconsistent with S on logicals (PR#316)
Peter Dalgaard BSA
p.dalgaard@biostat.ku.dk
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...
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._