findInterval
searches in a vector of »ranges« for the interval that a given value belongs to. # | | | | ranges <- c(0 , 2.5 , 6.5 , 10 ); quality <- c( 'low' , 'medium', 'high' ) # | | | | values <- c( 4, 1, 7, 8, 6); intervals<- findInterval(values, intervals); quality[intervals] # # "medium" "low" "high" "high" "medium"
findInterval
function can be used in switch
statement to test for ranges.