[Rd] suggestion for ?factor

(Ted Harding) Ted.Harding at manchester.ac.uk
Mon Aug 9 17:37:57 CEST 2010


Hi Folks.
May I suggest a small addition to ?factor -- this is not explicit
about how to force the ordering of levels in an ordered factor.

One can guess it, but I think it would be a good idea to spell it out.
For example, one can do:

  X <- c("Alf","Bert","Chris","Dave")
  F <- factor(X,levels=c("Dave","Alf","Chris","Bert"),ordered=TRUE)
  F
  # [1] Alf   Bert  Chris Dave 
  # Levels: Dave < Alf < Chris < Bert

So, where ?factor says:

  levels: an optional vector of the values that ?x? might have taken.
          The default is the unique set of values taken by
          'as.character(x)', sorted into increasing order of 'x'.
          Note that this set can be smaller than 'sort(unique(x))'.

it could include a bit extra so as to read:

  levels: an optional vector of the values that 'x' might have taken.
          The default is the unique set of values taken by
          'as.character(x)', sorted into increasing order of 'x'.
          Note that this set can be smaller than 'sort(unique(x))'.
          If 'levels=...' is present and 'ordered=TRUE', then the
          levels are ordered according to the order in which they
          are listed in 'levels'.

With thanks,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 09-Aug-10                                       Time: 16:37:50
------------------------------ XFMail ------------------------------



More information about the R-devel mailing list