Re: [R] peculiar matrices

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Sat 22 Oct 2005 - 08:03:11 EST


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?

"The business of the statistician is to catalyze the scientific learning process." - George E. P. Box    

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



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 08:09:56 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:17:21 EST