[Rd] reorder [stats] and reorder.factor [lattice]

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Aug 27 18:17:02 CEST 2004

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 at 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

More information about the R-devel mailing list