Reputation: 2505
This might be a stupid question but can I define a variable as a range so that the following would result in TRUE?
range1 <- range(0.001-0.002)
0.0015 %in% range1
Upvotes: 2
Views: 5594
Reputation: 8691
Why don't you write your own operator:
'%bw%'<-function(x,rng){
(x >= rng[1]) & (x <= rng[2])
}
rng<-range(c(2,5))
3 %bw% rng
TRUE
Upvotes: 2
Reputation: 66834
You can use findInterval
:
range1 <- c(0.001,0.002)
findInterval(0.0015,range1)==1
[1] TRUE
The interval is open on the upper limit by default though (ie 0.002 is not included).
Upvotes: 6