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

About this list Date view Thread view Subject view Author view Other groups

Subject: Re: data.frame(I(matrix)) ? (PR#388)
From: Thomas Lumley (thomas@biostat.washington.edu)
Date: Fri 24 Dec 1999 - 04:44:45 EST


Message-ID: <Pine.LNX.4.10.9912231839020.12924-100000@gimel.biostat.washington.edu>

On Thu, 23 Dec 1999 jens.oehlschlaegel-akiyoshi@mdfactory.de wrote:

>
>
> 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"
>

This is the Right Thing: we use the fact that multicolumn things can be a
single column of a data frame in logistic regression and extensively in
the survival analysis functions (and probably other places). However, it
does make it hard to turn a character matrix into a data frame. Perhaps
there should be an option of some sort?

        -thomas

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


About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b25 : Tue 04 Jan 2000 - 14:16:12 EST