Re: [R] Ordering in factors ...

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian D Ripley (ripley@stats.ox.ac.uk)
Date: Fri 28 Jun 2002 - 19:03:10 EST


Message-id: <Pine.GSO.4.44.0206280959500.24153-100000@auk.stats>

On Fri, 28 Jun 2002 j.logsdon@lancaster.ac.uk wrote:

> This is a trivial question probably buried in page 21 somewhere of An
> Idiot's Guide to R.
>
> In MASS(2) P26 for S-Plus you can write:
>
> ordered(income)<-c("Lo","Mid","Hi")
>
> but in R 1.5.0 you get the response to such an instruction:
>
> Error: couldn't find function "ordered<-"
>
> What's the fix to this? I have a series of models where the factors as
> reported need re-ordering so that the glm reports the coefficients with
> respect to the correct level. At the moment, while the solutions are
> identical, I actually have to do some arithmetic to show this.

There are scripts for MASS3 in the VR bundle, which give

income <- ordered(c("Mid","Hi","Lo","Mid","Lo","Hi","Lo"))
income
as.numeric(income)

inc <- ordered(c("Mid","Hi","Lo","Mid","Lo","Hi","Lo"),
    levels = c("Lo", "Mid", "Hi"))
inc

ordered factors in R are not quite the same as those in S.

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 16 Oct 2002 - 11:57:34 EST