[R] ordering of levels.
sundar.dorai-raj at PDF.COM
Mon Jul 26 21:07:05 CEST 2004
> Have the following factors with the following levels.
>  rank rank rank rank rank log log log rank sqrt sqrt sqrt log log rank
>  rank rank sqrt sqrt sqrt sqrt log log log log sqrt none none none none
>  none none none none sqrt none
> Levels: log none rank sqrt
> I would like to add an ordering to the levels.
> I tried with
> tmp$norm <-factor(tmp$norm,labels = c("none","sqrt","log","rank"),ordered=T)
>  log log log log log none none none log rank rank rank none none log
>  log log rank rank rank rank none none none none rank sqrt sqrt sqrt sqrt
>  sqrt sqrt sqrt sqrt rank sqrt
> Levels: none < sqrt < log < rank
> But this is not what I would like to have because the command not only superimposes an ordering but also changes the factors!
See ?factor or ?ordered which will help. I think what you want is:
lev <- c("none", "sqrt", "log", "rank")
tmp$norm <- ordered(tmp$norm, levels = lev)
tmp$norm <- factor(tmp$norm, levels = lev, ordered = TRUE)
Note the use of "levels" and not "labels".
More information about the R-help