[R] matrix lists

Agustin Lobo alobo at ija.csic.es
Wed Feb 27 10:59:36 CET 2002


Strident assertions?

My (non strident) assertion was about
matrices, not about matrix lists (which nobody said that would not exist).
In your example you omit the fact that
is.list(m) also results in TRUE:

> m <- list(a1=1:3, a2=4:6, a3=pi, a4=c("a","b","c"))
> dim(m) <- c(2,2)
> is.matrix(m)
[1] TRUE
> is.list(m)
[1] TRUE
> m[1,1]
[[1]]
NULL

So it's a matrix and it's a list.
The NULL result of m[1,1] (that I pointed to you), might be, as you say, a
bug. But in any case, objects such as m in the example
are not what most people would understand as a matrix.
It's a different type of object. And the original message said
" ...I tried to create a matrix from a list..." 
The "normal" matrix would yield FALSE for is.list():

> m <- list(a1=1:2, a2=4:5)
> m <- unlist(m)
> dim(m) <- c(2,2)
> is.matrix(m)
[1] TRUE
> is.list(m)
[1] FALSE
> m[1,1]
[1] 1



On Tue, 26 Feb 2002, Prof Brian D Ripley wrote:

> Perhaps the following example will help demonstrate that matrix lists do
> exist and do work up to a point, despite strident assertions on R-help to
> the contrary:
> 
> > m <- list(a1=1:3, a2=4:6, a3=pi, a4=c("a","b","c"))
> > dim(m) <- c(2,2)
> > m
>      [,1]        [,2]
> [1,] "Numeric,3" "Numeric,1"
> [2,] "Numeric,3" "Character,3"
> > is.matrix(m)
> [1] TRUE
> > m[[1,2]]
> [1] 3.141593
> > m[[2,2]]
> [1] "a" "b" "c"
> 
> In S m[2,2] extracts a sub-list, but that seems not to work correctly in R:
> neither does m[,2].  I am reporting that as a bug.
> 
> -- 
> 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 272860 (secr)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 






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



More information about the R-help mailing list