# Re: [R] figure out whether 1 is between two numbers

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Sun 19 Feb 2006 - 01:00:36 EST

On 2/18/2006 1:13 AM, Robert W. Baer, Ph.D. wrote:
> Try:
> (X>1 & Y<1) | (X<1 & Y>1)

This is a minor stylistic suggestion: when translating the mathematical expression (a < b < c), write it as (a < b) & (b < c). It has no effect on the outcome, but keeping the inequalities in the same direction makes the meaning more obvious.

If you do this, your expression becomes

(Y<1 & 1<X) | (X<1 & 1<Y)

and it's clear at a glance what's going on.

I think I originally read this suggestion in something written by Kernighan and/or Plauger, I can't claim credit for it.

Duncan Murdoch

>
> Rob
> ----- Original Message -----
> From: "Taka Matzmoto" <sell_mirage_ne@hotmail.com>
> To: <r-help@stat.math.ethz.ch>
> Sent: Friday, February 17, 2006 11:20 PM
> Subject: [R] figure out whether 1 is between two numbers
>
>

```>> Hi R users
>>
>> I have two variables (X and Y)
>>
>> X <-  rnorm(100,.7,.5)
>> Y <-  rnorm (100,.3,.1)
>>
>> I like to know whether 1 is between each pair of X and Y or not.
>>
>> Thanks
>>
>> TM
>>
>> ______________________________________________
>> R-help@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
>>
```

>
> ______________________________________________
> R-help@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

R-help@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 Received on Sun Feb 19 01:04:53 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:35 EST