Triamus
Triamus

Reputation: 2505

Define a variable as range

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

Answers (2)

Troy
Troy

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

James
James

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

Related Questions