[R] RE ordering levels

Torsten Hothorn Torsten.Hothorn at rzmail.uni-erlangen.de
Wed Dec 22 13:40:50 CET 2004


On Wed, 22 Dec 2004, Anne wrote:

> Sorry, sorry....
> of course
> levels(testf)[c(2,1,3)]
>
> will do the job
>

Anne,

note that `red' is coded as `blue' now:

R> testf <- factor(c("red","red","red","blue","blue","white"))
R> testf
[1] red   red   red   blue  blue  white
Levels: blue red white
R> levels(testf) <- levels(testf)[c(2,1,3)]
R> testf
[1] blue  blue  blue  red   red   white
Levels: red blue white

so you changed the data, not just the ordering of the levels. If there is
a reasonable ordering available, an ordered factor contructed via

ordered(c("red","red","red","blue","blue","white"), levels = c("red", "blue", "white"))
[1] red   red   red   blue  blue  white
Levels: red < blue < white

will do (the example here is silly, of course). But I guess you are
interested in a different ordering because of
some plotting problem or because of the specification of `baseline' levels
in linear models. For the latter one, have a deeper look at the `base'
argument of the `contr.treatment' function.

Best,

Torsten

> My excuses to all
>
> Anne
>
> PS I will meditate the following saying
> "la parole est d'argent et le silence est d'or"
>
> BONNES FETES A TOUS
> SEASONAL GREETINGS
>
>
> ----------------------------------------------------
> Anne Piotet
> Tel: +41 79 359 83 32 (mobile)
> Email: anne.piotet at m-td.com
> ---------------------------------------------------
> M-TD Modelling and Technology Development
> PSE-C
> CH-1015 Lausanne
> Switzerland
> Tel: +41 21 693 83 98
> Fax: +41 21 646 41 33
> --------------------------------------------------
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>




More information about the R-help mailing list