[R] peculiar matrices

From: Ben Bolker <bolker_at_ufl.edu>
Date: Sat 22 Oct 2005 - 07:32:44 EST

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 Received on Sat Oct 22 07:42:38 2005

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