Before sending to r-bugs I ask here:
> 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 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.
Is this a bug?
--
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-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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._