[R] does range of values in array include a third value?

Peter Ehlers ehlers at ucalgary.ca
Thu Feb 17 16:56:44 CET 2011


On 2011-02-17 07:36, Maas James Dr (MED) wrote:
>
> I'm using the range command to get the minimum and maximum values of an array as in
>
> x<- range(array_y)
>
> which gives me two values such as
>
> [1] -2 9
>
> I need to be able to test if this range of values includes a third value.  For example I'd like to query
>
> 1) does the range of -2 to 9 include 3, answer TRUE
> 2) does the range of -2 to 9 include -6, answer FALSE?
>
> All values could be negative or positive.  Is there a R function that will test this or do I need to programme it?  I have searched but not found one.

Here too you can use findInterval():

   findInterval( -2, range(array_y) ) == 1

You may want to set the 'rightmost.closed' argument to TRUE.

Peter Ehlers

>
> Thanks
>
> J
>
> ===============================
> Dr. Jim Maas
> University of East Anglia
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list