[R] subsetting an ordered factor

RenE J.V. Bertin rjvbertin at hotmail.com
Thu Sep 12 21:38:22 CEST 2002


On Thu, 12 Sep 2002 09:08:12 -0400, "Liaw, Andy" <andy_liaw at merck.com> wrote regarding "RE: [R]
subsetting an ordered factor"

8-) Well, it sort of make sense to me.  An ordered factor has a more defined
8-) domain than an unordered factor.  "!=" for unordered factor simply compare
8-) the labels, but for ordered factor it should mean "<" or ">".  Thus it
8-) returns NAs because R doesn't know how to do the comparison.


True, I can see it sort of makes sense, but is it a lot of sense? Isn't what you call an ordered
factor in fact non-existant in the sense that factors are by default and implicitly sorted
alphabetically? I see the analogy with "== NaN", but I think there may be a "problem" with Inf? (I
mean: "!=" exists but either "<" or ">" is undefined -- to forget Inf == Inf! )
Besides: why should factors be treated as numbers; cf. what happens with characters:

> kk <- c('a', 'b', 'c')
> kk[1]
[1] "a"
> kk[1]< kk[2]
[1] TRUE
> kk[kk!='d']
[1] "a" "b" "c"
## and:
> kk <- c( 'b', 'a', 'c')
## smaller/greater comparison is not based on the index but inherent to the elements like with
## an ordered factor:
> kk[1]< kk[2]
[1] FALSE
> kk[kk!='d']
[1] "b" "a" "c"

8-) This behavior is at least compatible with Splus.

That's another argument :) Are you sure R crashes everywhere Splus does? >8- [= mean, lame joke]
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list