Search notes:

R function: findInterval

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"
Github repository about-r, path: /functions/findInterval.R
The findInterval function can be used in switch statement to test for ranges.

See also

The dplyr function case_when.
Index to (some) R functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745539972, '3.21.106.4', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/findInterval(58): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78