I have 280 large (400MB) raster files in TIFF format. I am currently using terra::subst to modify the values of each raster file.
For example:
raster_matrix<-matrix(rep(101:200,10000*1600),nrow=1000*40,ncol=1000*40)
raster<-terra::rast(raster_matrix)
raster_subst <- terra::subst(raster, c(151, 152, 153), NA))
raster_subst <- terra::subst(raster_subst, c(160, 161, 162), 1))
raster_subst <- terra::subst(raster_subst, c(170, 171, 172), 2))
However, this process takes too long when applied to all 280 files. Is there a faster and more efficient way to achieve this?
This takes 1/3 of the time on the example dataset below. I could not recreate a SpatRaster as big as your example on my machine so am unsure how it will scale. Hopefully someone more knowledgeable will know how to reduce the time even further.