[R] as.ordered
Friedrich Schuster
mail at friedrich-schuster.de
Mon Oct 8 20:46:20 CEST 2007
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.
More information about the R-help
mailing list