From ripley at stats.ox.ac.uk  Fri Aug 27 18:17:02 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri Aug 27 18:17:07 2004
Subject: [Rd] reorder [stats] and reorder.factor [lattice]
In-Reply-To: <Pine.LNX.4.58.0408270918570.2608@public02.stat.wisc.edu>
Message-ID: <Pine.LNX.4.44.0408271705170.6872-100000@gannet.stats>

On Fri, 27 Aug 2004, Deepayan Sarkar wrote:

> It was recently pointed out on the lists that the S-PLUS Trellis suite has
> a function called reorder.factor that's useful in getting useful ordering
> of factors for graphs. I happily went ahead and implemented it, but it
> turns out that R (not S-PLUS) has a generic called reorder (with a method
> for "dendrogram"). Naturally, this causes R to think I'm defining a
> method for "factor", and gives a warning during check because of
> mismatching argument names.
> 
> Any suggestions as to what I should do? Retaining S compatibility doesn't
> seem to be an option. I could make a reorder method for "factor" (which
> sounds like a good option to me), or rename it to something like
> reorderFactor.

I am pretty sure you don't want to copy the Trellis call, which is

function(Factor, X, Function = mean, ...)

and suggests it dates from the days when S3 lookup could not distingush
functions from other objects by context, hence the capitalization.  Even
then, it is inconsistent with tapply etc which use FUN.

reorder.factor <- function(x, X, FUN=mean)

looks about right.  Another problem though: in Trellis reorder.factor 
doesn't just reorder the factor, it makes it an ordered factor.  I don't 
really see why, especially as the modelling functions assume that ordered 
means equally spaced.  If this is to be used more generally (as Kjetil 
Halvorsen suggests) then it should record the scores used to do the 
ordering in an attribute.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] reorder [stats] and reorder.factor [lattice]
Prof Brian Ripley