gregory_r_warnes@groton.pfizer.com
2004-Mar-26 23:09 UTC
[Rd] cbind/rbind fail on matrixes containing lists (PR#6702)
Today's R 1.9.0 beta:> 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,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> version_ platform sparc-sun-solaris2.8 arch sparc os solaris2.8 system sparc, solaris2.8 status beta major 1 minor 9.0 year 2004 month 03 day 26 language R Gregory R. Warnes Manager, Non-Clinical Statistics Pfizer Global Research and Development Tel: 860-715-3536 LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}
Thomas Lumley
2004-Mar-26 23:30 UTC
[Rd] cbind/rbind fail on matrixes containing lists (PR#6702)
Yep, bind.c:do_bind has switch(mode) { case NILSXP: case LGLSXP: case INTSXP: case REALSXP: case CPLXSXP: case STRSXP: break; default: errorcall(call, "cannot create a matrix from these types"); } Looks like a fairly simple fix to me. -thomas
Prof Brian Ripley
2004-Mar-27 09:00 UTC
[Rd] cbind/rbind fail on matrixes containing lists (PR#6702)
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) 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. On Fri, 26 Mar 2004 gregory_r_warnes@groton.pfizer.com wrote:> > Today's R 1.9.0 beta: > > > 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,1]) > [1] "list"Why not class(m1)? It should be the same ....> > 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 > > > version > _ > platform sparc-sun-solaris2.8 > arch sparc > os solaris2.8 > system sparc, solaris2.8 > status beta > major 1 > minor 9.0 > year 2004 > month 03 > day 26 > language R-- Brian D. Ripley, ripley@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
ripley@stats.ox.ac.uk
2004-Mar-27 09:03 UTC
[Rd] cbind/rbind fail on matrixes containing lists (PR#6702)
On Fri, 26 Mar 2004, Thomas Lumley wrote:> On Fri, 26 Mar 2004, Thomas Lumley wrote: > > > > > Yep, bind.c:do_bind has > > > > switch(mode) { > > case NILSXP: > > case LGLSXP: > > case INTSXP: > > case REALSXP: > > case CPLXSXP: > > case STRSXP: > > break; > > default: > > errorcall(call, "cannot create a matrix from these types"); > > } > > > > > > Looks like a fairly simple fix to me. > > Not any more it doesn't. bind.c:AnswerType puts lists together with > pairlists and who knows what else in its `other' class, so a bit more > thought and coding is needed. > > It should be fairly straightforward, but it's not a localised change.That's not the main problem area: the actual cbind code does not handle vector lists. I've treated it as a documentation fix / enhancement request. Brian -- Brian D. Ripley, ripley@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
Warnes, Gregory R
2004-Mar-31 20:55 UTC
[Rd] cbind/rbind fail on matrixes containing lists (PR#6702)
Hello Brian,> -----Original Message----- > From: Prof Brian Ripley [mailto:ripley@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 ....But it is not:> class(m1)[1] "matrix"> class(m1[1,1])[1] "list" -Greg LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}