[Rd] cbind/rbind fail on matrixes containing lists (PR#6702)

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Mar 31 20:59:54 CEST 2004


Since 1.9.0 got delayed, we have written the code for this case (today).  
But only vector lists, and not some of the language objects (pairlists)  
you can make matrices of.

The example you give does not work.


On Wed, 31 Mar 2004, Warnes, Gregory R wrote:

> 
> Hello Brian,
> 
> > -----Original Message-----
> > From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk]
> > 
> > There are no `matrixes containing lists'.  There are lists 
> > which are also 
> > matrices, but their contents are the vector elements  (unless 
> > you meant 
> > that it was a list of lists, which seems not be the case in 
> > your example).
> > In the absence of a reproducible example, it is not clear to 
> > me exactly 
> > what you want to do.
> > 
> > Here is a list matrix example:
> > 
> > A <- matrix(as.list(1:4), 2, 2)
> > cbind(A, A)
> > 
> 
> I was, in fact, using a matrix containing "list" elements.  
> 
> I did fail to provide the definition of my 'list matrix'.  It was simply:
> 
> > m1 <- matrix(list(NA),4,4)
> > m1
>      [,1] [,2] [,3] [,4]
> [1,] NA   NA   NA   NA  
> [2,] NA   NA   NA   NA  
> [3,] NA   NA   NA   NA  
> [4,] NA   NA   NA   NA  
> > class(m1)
> [1] "matrix"
> > class(m1[1,1])
> [1] "list"
> > cbind(m1,m1)
> Error in cbind(...) : cannot create a matrix from these types
> > rbind(m1,m1)
> Error in rbind(...) : cannot create a matrix from these types
> 
> > It appears to be intentional (line 950 of bind.c and the actual cbind
> > code), in which case this is a documentation bug and I have 
> > altered the
> > docs.
> 
> Odd.
> 
> > Why not class(m1)?  It should be the same ....

Sorry, of course not.  typeof() would have been best.

> But it is not:
> 
> > class(m1)
> [1] "matrix"
> > class(m1[1,1])
> [1] "list"
> 
> -Greg
> 
> 
> LEGAL NOTICE
> Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
> 
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list