Bug in inequalities involving ordered factors (PR#232)

Ross Ihaka ihaka@stat.auckland.ac.nz
Mon, 26 Jul 1999 16:34:33 +1200 (NZST)


Here is a QuickFix (TM) which probably needs more careful thought.
(It looks like Ops.ordered has only been partially implemented).

Ops.ordered <-
function (e1, e2)
{
    nas <- is.na(e1) | is.na(e2)
    ord1 <- FALSE
    ord2 <- FALSE
    if (nchar(.Method[1])) {
        l1 <- levels(e1)
        ord1 <- TRUE
    }
    if (nchar(.Method[2])) {
        l2 <- levels(e2)
        ord2 <- TRUE
    }
    if (all(nchar(.Method)) && (length(l1) != length(l2) ||
        !all(sort(l2) == sort(l1))))
        stop("Level sets of factors are different")
    if (ord1 && ord2) {
        e1 <- codes(e1)
        e2 <- codes(e2)
    }
    else if (!ord1) {
        e1 <- match(e1, l2)
        e2 <- codes(e2)
    }
    else if (!ord2) {
        e2 <- match(e2, l1)
        e1 <- codes(e1)
    }
    value <- get(.Generic, mode = "function")(e1, e2)
    value[nas] <- NA
    value
}

I have committed this in the development version, but it probably needs
more thought than I have time for at present.

	Ross
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._