[R] data.frame
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Tue Jun 8 00:11:30 CEST 1999
Chong Gu <chong at stat.purdue.edu> writes:
> I am not sure if I should call this a bug or just a design
> imperfection.
>
> I have noticed that the data.frame function does not preserve the
> integrity of multivariate components. Here is a simple illustration:
>
> > x <- matrix(1:6,3,2)
> > y <- 1:3
> > z <- data.frame(x=x,y=y)
> > z$x
> # NULL
> > z$y
> # [1] 1 2 3
>
> One can however get by that by using model.frame:
>
> > zz <- model.frame(~x+y)
> > zz$x
> # [,1] [,2]
> # [1,] 1 4
> # [2,] 2 5
> # [3,] 3 6
>
> I was expecting data.frame to behave like this.
You're not the first... This apparently goes back to a design decision
that data.frame be used to coerce matrices to data frames. You can get
the desired behaviour with the I() function:
> z <- data.frame(x=I(x),y=y)
> z$x
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
attr(,"class")
[1] "AsIs"
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list