[R] matrix

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Sun Apr 23 21:36:41 CEST 2000


gb <gb at stat.umu.se> writes:

> Is there a reason for the following behaviour?
> 
> > x <- matrix(1:6, ncol = 1)
..
> > is.matrix(x[1:2,])
> [1] FALSE

Yes, there's a reason. Whether it's a good one is debatable, but it
has pervaded so much existing S (and R) code that it is not likely to
get changed. A single matrix column is converted to a vector and
generally when subsetting arrays, indices corresponding to extents of
length one are dropped. Note however that the behaviour can be
overridden:

> x <- matrix(1:6, ncol = 1)
> is.matrix(x[1:2,,drop=F])
[1] TRUE


-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list