From maechler at stat.math.ethz.ch  Tue May 13 11:09:06 2003
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Tue May 13 10:09:18 2003
Subject: [Rd] range checking
In-Reply-To: <Pine.LNX.4.21.0305130955360.14452-100000@tolstoy.newcastle.edu.au>
References: <Pine.LNX.4.21.0305130955360.14452-100000@tolstoy.newcastle.edu.au>
Message-ID: <16064.43042.566272.18532@gargle.gargle.HOWL>

>>>>> "Robert" == Robert King <robert.king@newcastle.edu.au>
>>>>>     on Tue, 13 May 2003 10:01:49 +1000 (EST) writes:

    Robert> I'm tidying up the gld package at the moment, and
    Robert> the following is my best effort at checking if
    Robert> values are outside the range of the functi (which is
    Robert> [0,1] in this case).

    Robert> It seems incredibly messy - is there something
    Robert> better?

    Robert> outside.range <- !as.logical(((p<1)*(p>0))|(sapply(p,
    Robert>          all.equal,1)"TRUE")|(sapply(p, all.equal, 0)"TRUE"))

why not just

     outside.range <- !all(0 <p & p <1)
or   outside.range <- !all(0 <p) || !all(p <1)
or   outside.range <- any(p < 0) || any(p > 1)
or   outside.range <- any(p < 0 | p > 1)

{using the double && or || is a short cut and may be faster on
 average particularly when the first condition is more probable
 than the fast}

Martin


[Rd] range checking
Martin Maechler