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

From: Prof Brian Ripley <>
Date: Sat 28 Aug 2004 - 02:17:02 EST

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,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
Received on Sat Aug 28 02:20:51 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 08:59:24 EST