Message-ID: <CAAmySGO-3jhbsK0FsVqM5iNUk_BLSU6b9Oh7yAi5xknAzOXOtA@mail.gmail.com>
Date: 2012-12-01T16:55:12Z
From: R. Michael Weylandt
Subject: screen if a value is within range
In-Reply-To: <1354380655.87935.YahooMailNeo@web163105.mail.bf1.yahoo.com>
15 < a & a < 20
Wrap it in a function if you like:
in_interval <- function(x, interval){
stopifnot(length(interval) == 2L)
interval[1] < x & x < interval[2]
}
in_interval(a, c(15, 20))
Cheers,
Michael
On Sat, Dec 1, 2012 at 4:50 PM, Andras Farkas <motyocska at yahoo.com> wrote:
>
> could you please give me some pointers on how I could make R screen for a value if it falls within a certain range?
> I looked at the subset function, but is not doing it, perhaps because I only have 1 value to screen?
>
> aptreciate the input
>
> ex:
> a <-16.5
> I would like to screen to see if a is within the range of 15 to 20, (which it is:-)), and I would like the code to return a value of 1 if a is within the specified range or 0 if it is not.
>