From thomas@biostat.washington.edu  Tue Aug 12 17:28:13 1997
From: thomas@biostat.washington.edu (Thomas Lumley)
Date: Tue, 12 Aug 1997 09:28:13 -0700 (PDT)
Subject: R-alpha: 'Matrix' & 'matrix' Class
In-Reply-To: <199708120732.JAA00579@sophie.ethz.ch>
Message-ID: <Pine.SUN.3.95.970812090421.777A-100000@spock>

> 
> I disagree (I think this is a rare thing with you Thomas..).
> ----------
> 1) Lest I misunderstood something,
>   you mean that	for matrices 'x',
> 	  x[,1]
>   would be a 1--column matrix instead of a vector ?
>   IMHO, this is ugly, and is really just logical if you come from a strict
>   matrix thinker's corner which is the case for  matlab users, and maybe even
>   mathematicians and the like (I'm one myself),
>   but not for an average person analyzing  statistical data.

I'm not opposed to a matrix class, but I do think drop=FALSE should be the
default for arrays (I'm not as sure about data frames, but I do think it
is reasonable that one row of a data frame should be a data frame). The
reason is that the *current* behaviour of [ with drop=TRUE in S and R
breaks a lot of S code. 

I have found this particular problem in code written for other people to
use by people from a wide range of backgrounds. For example, Harald
Fekjaer's addreg library, Adrian Raftery's bayesian model averaging code,
and even an early version of Brian Ripley's linear discrimination
function. These functions break because they assume that x[vec,] is a
matrix even when it has a single row.  It rarely seems to matter if x[,1]
is a matrix or a vector, but it is important if x[1,] is a vector. 

For data analysis I don't think it matters much, though I agree it is a
little ugly for x[,1] to be a matrix. For programming I think that drop=F
is the same sort of incompatibility as the R scoping rules: one that
fixes, rather than breaks, S code. Of course people could just use drop=F,
the way they could just pass variables into nested functions explicitly.
The problem is that most of us don't, and it's a remarkably difficult bug
to find.

I may well be wrong, of course. ;-)


Thomas Lumley
-----------------------------------------------------+------
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel 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-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: 'Matrix' & 'matrix' Class
Thomas Lumley