From p.dalgaard at biostat.ku.dk  Mon Dec  8 18:50:31 2003
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Mon Dec  8 18:49:33 2003
Subject: [Rd] matrix coercion, logical -> character
In-Reply-To: <Pine.LNX.4.44.0312081607300.19904-100000@gannet.stats>
References: <Pine.LNX.4.44.0312081607300.19904-100000@gannet.stats>
Message-ID: <x2brqjp5aw.fsf@biostat.ku.dk>

Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:

> On 8 Dec 2003, Peter Dalgaard wrote:
> 
> > 
> > Anyone know whether this is intentional, and by which rationale?
> > (R-devel on RedHat, but hardly new)
> 
> It is documented:
> 
>      'as.matrix' is a generic function. The method for data frames will
>      convert any non-numeric column into a character vector using
>      'format' and so return a character matrix.

and for apply:

     If 'X' is not an array but has a dimension attribute, 'apply'
     attempts to coerce it to an array via 'as.matrix' if it is
     two-dimensional (e.g., data frames) or via 'as.array'.

explains why apply(...., which) got in trouble

> Remember than not some long ago you could not have logical columns in data 
> frames: they were coerced to factors.
> 
> It would be easy to change to allow numeric, logical or character 
> matrices.

Yes. That was the direction in which I was hinting. It does seem a bit
like a leftover, and applying which() over a set of logical
columns is not unlikely to be useful in practice.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] matrix coercion, logical -> character
Peter Dalgaard