[R] peculiar matrices

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Oct 22 09:08:33 CEST 2005


Just to add to what others have said, don't confuse how an object is 
printed with its structure.  This must be intentional as the internal code 
has a specific section just to print list arrays/matrices.

?matrix has the first argument as

     data: an optional data vector.

and a list is a vector.


I did find the following incorrect statement in R-lang:

   As the elements of a vector or matrix must be of the same type there are
   multiple types of @code{NA} values.

That is missing `atomic' before `vector'.  Some parts of the R 
documentation were written before lists were vectors and so assume vectors 
are atomic, but instances of that assumption as rare nowadays.  If you 
find one, please report it.


On Fri, 21 Oct 2005, Ben Bolker wrote:

>
> As far as I can tell from reading The Fine Documentation
> (R Language Definition and Intro to R), matrices are supposed
> to be of homogeneous types.  Yet giving matrix() an inhomogeneous
> list seems to work, although it produces a peculiar object:
>
> v = list(1:3,4,5,"a")
> m = matrix(v,nrow=2)
> m
>
>     [,1]      [,2]
> [1,] Integer,3 5
> [2,] 4         "a"
>
>
> m[1,]
>
> [[1]]
> [1] 1 2 3
>
> [[2]]
> [1] 3
>
> (this is R 2.1.1, running under Linux)
>  Should there be a check/error? Or is this just analogous to
> the joke about going to the doctor and saying "it hurts when
> I do this", and the doctor saying "well then, don't do that"?

-- 
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-help mailing list