Re: [R] ordering of levels.

From: Wolski <wolski_at_molgen.mpg.de>
Date: Tue 27 Jul 2004 - 05:19:25 EST

Hi!
Thanks a lot.
Eryk

On 7/26/2004 at 2:07 PM Sundar Dorai-Raj wrote:

>>>Wolski wrote:
>>>
>>>> Hi!
>>>> Have the following factors with the following levels.
>>>> tmp$norm
>>>> [1] rank rank rank rank rank log log log rank sqrt sqrt sqrt log
>>>log rank
>>>> [16] rank rank sqrt sqrt sqrt sqrt log log log log sqrt none none
>>>none none
>>>> [31] none none none none sqrt none
>>>> Levels: log none rank sqrt
>>>>
>>>> I would like to add an ordering to the levels.
>>>> none<sqrt<log<rank
>>>>
>>>> I tried with
>>>> tmp$norm <-factor(tmp$norm,labels =
>>>c("none","sqrt","log","rank"),ordered=T)
>>>>
>>>>>tmp$norm
>>>>
>>>> [1] log log log log log none none none log rank rank rank none
>>>none log
>>>> [16] log log rank rank rank rank none none none none rank sqrt sqrt
>>>sqrt sqrt
>>>> [31] 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!
>>>>
>>>> Eryk
>>>>
>>>
>>>Eryk,
>>> 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)
>>>
>>>or
>>>
>>>tmp$norm <- factor(tmp$norm, levels = lev, ordered = TRUE)
>>>
>>>Note the use of "levels" and not "labels".
>>>
>>>--sundar

Dipl. bio-chem. Eryk Witold Wolski @ MPI-Moleculare Genetic

Ihnestrasse 63-73 14195 Berlin       'v'    
tel: 0049-30-83875219               /   \    
mail: wolski_at_molgen.mpg.de        ---W-W----    http://www.molgen.mpg.de/~wolski

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 27 05:43:13 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:16 EST