Re: [R] peculiar matrices

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 22 Oct 2005 - 17:08:33 EST

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@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Oct 22 17:15:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:46 EST