Reclassify raster with multiple ranges in R
It works better if there are no gaps in the reclassification matrix
#matrix with rules reclass
m<-matrix(c(0,1,NA,
1,6,1,
6,8,3,
8,9,2,
9,13,1,
13,15,2,
15,19,3,
19,20,2,
20,23,3,
23,24,3,
24,25,3,
25,32,3,
32,33,3,
33,38,3,
38,39,2,
39,40,3,
40,41,2,
41,Inf,3), ncol=3, byrow=TRUE)
#r2 with reclass
r2<-raster::reclassify(x=r, rcl=m, include.lowest=TRUE)
This has to be done like that with decimal numbers. With integers, it could be allowed to specify it the way you want think about it, where the interval is open at both sides, and from
and to
can be the same value, but that is currently not the case.