Wolfram Fischer
2006-Nov-29 08:59 UTC
[R] Why the factor levels returned by cut() are not ordered?
What is the reason, that the levels of the factor returned by cut() are not marked as ordered levels?> is.ordered( cut( breaks=3, sample(10 ) ) )FALSE> help(factor)... If 'ordered' is 'TRUE', the factor levels are assumed to be ordered. ... Wolfram
Petr Pikal
2006-Nov-29 09:26 UTC
[R] Why the factor levels returned by cut() are not ordered?
Hi it is not stated that the cut shall return ordered factor. If you want you can use ordered(cut( breaks=3, sample(10 ) )) or modify code for cut.default to accept ordered switch. HTH Petr On 29 Nov 2006 at 9:59, Wolfram Fischer wrote: Date sent: Wed, 29 Nov 2006 09:59:36 +0100 From: Wolfram Fischer <wolfram at fischer-zim.ch> To: r-help at stat.math.ethz.ch Subject: [R] Why the factor levels returned by cut() are not ordered?> What is the reason, that the levels of the factor > returned by cut() are not marked as ordered levels? > > > is.ordered( cut( breaks=3, sample(10 ) ) ) > FALSE > > > help(factor) > ... > If 'ordered' is 'TRUE', the factor levels are assumed to be > ordered. ... > > Wolfram > > ______________________________________________ > 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 and provide commented, > minimal, self-contained, reproducible code.Petr Pikal petr.pikal at precheza.cz
Bjørn-Helge Mevik
2006-Nov-29 09:33 UTC
[R] Why the factor levels returned by cut() are not ordered?
Wolfram Fischer wrote:> What is the reason, that the levels of the factor > returned by cut() are not marked as ordered levels?I don't know, but you can always make it ordered with ordered(cut(breaks = 3, sample(10)))>> help(factor) > ... > If 'ordered' is 'TRUE', the factor levels are assumed to be ordered. > ...The help file for factor() probably doesn't tell you much about how cut() works. :-) -- Bj?rn-Helge Mevik
Peter Dalgaard
2006-Nov-29 11:08 UTC
[R] Why the factor levels returned by cut() are not ordered?
Wolfram Fischer wrote:> What is the reason, that the levels of the factor > returned by cut() are not marked as ordered levels? > > >> is.ordered( cut( breaks=3, sample(10 ) ) ) >> > FALSE > >It would arguably be the Right Thing, but there would be complications in modeling, where ordered factors result in polynomial contrast coding. (This, in my opinion, is a design mistake inherited from S, but it's not easy to change at this stage.)>> help(factor) >> > ... > If 'ordered' is 'TRUE', the factor levels are assumed to be ordered. > ... > > Wolfram > > ______________________________________________ > 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 > and provide commented, minimal, self-contained, reproducible code. >-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Petr Pikal
2006-Nov-29 14:18 UTC
[R] Why the factor levels returned by cut() are not ordered?
On 29 Nov 2006 at 12:08, Peter Dalgaard wrote: Date sent: Wed, 29 Nov 2006 12:08:21 +0100 From: Peter Dalgaard <P.Dalgaard at biostat.ku.dk> To: Wolfram Fischer <wolfram at fischer-zim.ch> Copies to: r-help at stat.math.ethz.ch Subject: Re: [R] Why the factor levels returned by cut() are not ordered?> Wolfram Fischer wrote: > > What is the reason, that the levels of the factor > > returned by cut() are not marked as ordered levels? > > > > > >> is.ordered( cut( breaks=3, sample(10 ) ) ) > >> > > FALSE > > > > > It would arguably be the Right Thing, but there would be complications > in modeling, where ordered factors result in polynomial contrast > coding. (This, in my opinion, is a design mistake inherited from S, > but it's not easy to change at this stage.)Well what about to change cut.default if (codes.only) code else factor(code, seq(labels), labels) to if (codes.only) code else factor(code, seq(labels), labels, ...) which enables to use ordered switch> is.ordered( cut( breaks=3, sample(10 ), ordered=T ) )[1] TRUE Without this the result is same as before (I believe :-) Petr >> help(factor) >> >> ... > If 'ordered' is 'TRUE', the factor levels are assumed to > be ordered. > ... > > Wolfram > > > ______________________________________________ > > 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 > and > provide commented, minimal, self-contained, reproducible code. > > > > -- > O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B > c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K > (*) \(*) -- University of Copenhagen Denmark Ph: (+45) > 35327918 > ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) > 35327907 > > ______________________________________________ > 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 and provide commented, > minimal, self-contained, reproducible code.Petr Pikal petr.pikal at precheza.cz