data.frame(I(matrix)) ? (PR#388)

jens.oehlschlaegel-akiyoshi@mdfactory.de jens.oehlschlaegel-akiyoshi@mdfactory.de
Thu, 23 Dec 1999 19:17:44 +0100 (MET)



I observe dificulties with using data.frame(I(matrix))

> mat <- matrix(letters, 2, 2)
> dimnames(mat) <- list(c(1:2), c("x","y"))
> mat
  x   y
1 "a" "c"
2 "b" "d"

> dd <- data.frame(I(mat))
> ddd
  I.mat..x I.mat..y
1        a        a
2        b        b
3        c        c

doesn't look too bad,
but,
has only one column name:

> dimnames(dd)
[[1]]
[1] "1" "2"

[[2]]
[1] "I.mat."

and unexpected structure
> str(ddd)
`data.frame':     3 obs. of  1 variable:
 $ I.mat.: chr [1:3, 1:2] "a" "b" "c" "a" "b" "c"
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr  "x" "y"
  ..- attr(*, "class")= chr "AsIs"
>

column 1 is a matrix
> ddd[,1]
     x   y
[1,] "a" "a"
[2,] "b" "b"
[3,] "c" "c"
attr(,"class")
[1] "AsIs"

This dataframe is not a simple list with each element representing one
column.

Consequently, e.g.

> sapply(ddd, FUN=function(x)x)
     I.mat.
[1,] "a"
[2,] "b"
[3,] "c"
[4,] "a"
[5,] "b"
[6,] "c"

is no longer a matrix.


platform Windows
arch     x86
os       Win32
system   x86, Win32
status
major    0
minor    90.1
year     1999
month    December
day      15
language R

--
Dr. Jens Oehlschlägel-Akiyoshi
MD FACTORY GmbH
Bayerstrasse 21

80335 München

Tel.: 089 545 28-27
Fax.: 089 545 28-10
http://www.mdfactory.de

Standard Disclaimers: Opinions expressed here are personal
and are not otherwise represented.


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