From rgentlem@jimmy.harvard.edu  Mon Apr 23 19:12:20 2001
From: rgentlem@jimmy.harvard.edu (Robert Gentleman)
Date: Mon, 23 Apr 2001 14:12:20 -0400
Subject: [Rd] several bugs (PR#918) lists and matrices
In-Reply-To: <200104231757.f3NHvWZ379277@surfer.sbm.temple.edu>; from Rich Heiberger on Mon, Apr 23, 2001 at 01:57:32PM -0400
References: <200104231757.f3NHvWZ379277@surfer.sbm.temple.edu>
Message-ID: <20010423141220.X25202@jimmy.harvard.edu>

On Mon, Apr 23, 2001 at 01:57:32PM -0400, Rich Heiberger wrote:
> ## Thomas rightly points out that list() is not the best structure for
> ## homogeneous data.  My example was the simplest that generated the
> ## error of a matrix structure that that doesn't work.  The application
> ## that this is simplified from needs lists because the data isn't
                                                          data aren't (?)
> ## homogeneous.  I am attempting to write a missing value class, where
> ## each item is a list.  In the simplest instance, if the datum is missing
> ## then the attribute contains the reason.
> ## 
> ## Both of the 'bugs'/'unimplemented features'
> ## 3. a <- matrix(list(1,2,3,4,5,6), 2, 3)
> ## 6. bug in "[" for lists
> ## show up in this example.  Thus
> 
> x <- list(1,2,3,4,5,6)
> dim(x) <- c(2,3)
> x[[2,3]] <- NA
> attr(x[[2,3]],"mv") <- "absent"
> x
> for(i in x) print(i)
> x[2,]
> x[1,1]
> x[2,3]


  Yes, it appears to be either a bug or perhaps an unimplemented
  feature (or possibly an unimplemented bug). The problem with the S
  version of this is that the following doesn't work the same as the
  above (I might argue that it should)
> x<-matrix(1:6,nc=3)
> x
     [,1] [,2] [,3] 
[1,]    1    3    5
[2,]    2    4    6
> x[[2,3]]<-NA
> x
     [,1] [,2] [,3] 
[1,]    1    3    5
[2,]    2    4   NA
> attr(x[[2,3]],"mv") <- "absent"
> for(i in x) print(i)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] NA

  I am uncertain as to why you want to put dimensions on a list? It
  doesn't make it a matrix. That said we can duplicate the behaviour
  but I'm not sure that it is worth introducing the confusion that
  ought to follow.

  For my favorite silly example:
> dim(mean)<-c(2,2) 
Warning messages:
  assigning "mean" masks an object of the same name on database 2
> mean
           [,1] [,2] 
[1,] missing, 0     
[2,] 0          {, 5
attr(, "names"):
[1] "x"     "trim"  "na.rm" ""     
> is.matrix(mean)
[1] T
> mean(1:10)
[1] 5.5
> 
    Just because you can does not necessarily mean that you should.

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

-- 
+---------------------------------------------------------------------------+
| Robert Gentleman                 phone : (617) 632-5250                   |
| Associate Professor              fax:   (617)  632-2444                   |
| Department of Biostatistics      office: M1B28
| Harvard School of Public Health  email: rgentlem@jimmy.dfci.harvard.edu   |
+---------------------------------------------------------------------------+
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] several bugs (PR#918) lists and matrices
Robert Gentleman