[R] Between the values

Dan Davison davison at stats.ox.ac.uk
Tue Aug 12 14:23:54 CEST 2008


On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth wrote:
> Hi R,
> 
>  
> 
> This is a very trivial one....
> 
>  
> 
> C=0.1
> 
>  
> 
> I want to check whether my value of C is between 0 and 1 exclusively....
> I don't want to use (C>0 & C<1). And I can't use a single statement like
> (0<C<1). Is there a between function? Or how do we specify from 0 to 1?
> Does %in% help me?

If you don't like (C > 0 && C < 1), then just write your own function
is.between(x, low, high) (NB1 you've basically written it already; NB2
single '&' for the vectorised version 'are.between'). People's
personal tastes about what's desirable will vary, and anyway it's good
practice to build up your own personal library of
functions. Ultimately if you have a high quality collection of related
functions for working on a particular sort of problem, then you should
publish them as an R package on CRAN.

Dan

> 
>  
> 
>  
> 
> Many Thanks,
> 
> Shubha
> 
>  
> 
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
> 
> ______________________________________________
> 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.

-- 
www.stats.ox.ac.uk/~davison



More information about the R-help mailing list