[R] as.ordered

Birgit Lemcke birgit.lemcke at systbot.uzh.ch
Tue Oct 9 11:14:21 CEST 2007


Hello Friedrich,

thanks for your help and it is really not important that the solution  
is elegant. Important is only that there is a solution.

But I still have some problems with this topic.

#I tried as you suggested to order the vectors separately. My first  
problem is that my data is a data.frame:

data.frame':	348 obs. of  1 variable:
$ bracts.length.relative.to.flower...............Min: Factor w/ 4  
levels "1","2","3","4": 2 3 3 3 3 2 1 4 3 2 ...

     bracts.length.relative.to.flower...............Min
1                                                    2
2                                                    3
3                                                    3
4                                                    3
5                                                    3
6                                                    2


#I tried to convert it to a vector using this:

bract.awnMin<-as.vector(bract.awnMin)

'#and then to use sort.list:

sort.list(bract.awnMin)
Fehler in sort.list(bract.awnMin) :
   'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?

#if I try to use the following for the data.frame with two variables,  
it works well.

bract.awn[order(bract.awn[,1]),]

#but I have tu order both variables an therefore I should do that  
separately and then use cbind.

Can somebody help me with my problem please?

Greetings

Birgit






Am 08.10.2007 um 20:46 schrieb Friedrich Schuster:

>
> Hello,
>
> (Warning. This might not be the most complete or elegant solution ...)
>
> If you want a sorted dataframe: look here for example
> http://tolstoy.newcastle.edu.au/R/help/05/02/12391.html
>
> To convert the factors from a data frame, you have to call  
> as.ordered for
> each factor separately (not for the dataframe).
> To convert  two factors a and b and merge them into a new dataframe:
> newFrame <- as.data.frame(cbind(as.ordered(a),as.ordered(b)))
> l
> For a larger number of factors this can be done with a loop or  
> better one of
> the "apply"-functions.
>
> Hope this helps,
> Friedrich Schuster
>
>
> Birgit Lemcke wrote:
>>
>> Hello Members,
>>
>> I try to convert variables in a data.frame (bract.awn) in the class
>> ordered.
>>
>> str(bract.awn)
>> 'data.frame':	348 obs. of  2 variables:
>> $ bracts.length.relative.to.flower...............Min: Factor w/ 4
>> levels "1","2","3","4": 2 3 3 3 3 2 1 4 3 2 ...
>> $ bract.awn.relative.to.body.................Max    : Factor w/ 4
>> levels "1","2","3","4": 1 3 2 1 4 1 1 1 1 1
>>
>>
>> I tried this:
>>
>> bract.awn<-as.ordered(bract.awn)
>>
>> Fehler in sort.list(unique.default(x), na.last = TRUE) :
>>    'x' must be atomic for 'sort.list'
>> Have you called 'sort' on a list?
>>
>> What am I doing wrong?
>>
>> Thanks a lot in advance.
>>
>> Regards
>>
>> Birgit
>>
>>
>>
>> Birgit Lemcke
>> Institut für Systematische Botanik
>> Zollikerstrasse 107
>> CH-8008 Zürich
>> Switzerland
>> Ph: +41 (0)44 634 8351
>> birgit.lemcke at systbot.uzh.ch
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/as.ordered- 
> tf4589454.html#a13102513
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting- 
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke at systbot.uzh.ch



More information about the R-help mailing list