[R] peculiar matrices

Berton Gunter gunter.berton at gene.com
Sat Oct 22 00:03:11 CEST 2005


matrix coerces it's arguments to a single mode first. Try mode(m) -- iit's a
list (with a dim attribute). If you print each entry of m separately, you'll
find they're all lists.

As the docs say, if either of nrow or ncol aren't given, it tries to "infer"
what they should be from the data and other parameter. Haven't a clue what
the algorithm does, but given your data, it made a guess. What would you
have wanted it to give that makes any more sense?

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ben Bolker
> Sent: Friday, October 21, 2005 2:33 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] peculiar matrices
> 
> 
> 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"?
> 
>   Ben Bolker
> 
> ______________________________________________
> R-help at 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
>




More information about the R-help mailing list