Skip to content

Find all numbers in a certain interval

2 messages · Antje, Duncan Murdoch

#
Hi,

sorry, but it shouldn't be "different". The result should be the same but I was 
looking if there is a method I can use...

# having a function defined like baptiste proposed:
isIn <-
function (interval, x)
{
     (x > min(interval)) & (x < max(interval))
}

#----------------------


a <- rnorm(100)

# it's simply more human readable if I can write

which( isIn( c(-0.5, 0.5), a) )

# instead of

which( a > -0.5 & a < 0.5 )

Thanks to baptiste! So there is no method available doing this and I have to 
define this by myself. That's all I wanted to know :-)

Antje


markleeds at verizon.net schrieb:
#
Antje wrote:
Along the lines I suggested before, I'd suggest a function ordered(...) 
(or increasing()?) that could be called as

ordered(-0.5, x, 0.5)

If you do write this, be careful about how you handle recycling of values.

Duncan Murdoch