The task: I'm creating a function to assess flood damage in R. The inputs are: - Dataframe with water depth values and corresponding damage values in percentage. - Raster representing water depth The raster values must be approximated to the closest value in the first column of the df and then create a new raster with damage values using corresponding values from the second column). library(raster) damage <- cbind(c(0.0,0.2,0.4,0.6,0.8,1.0),c(0, 5, 10, 40, 70, 100)) r.wd <- raster(myraster.tif) I've tried using `which.min(abs(damage[,1]-r.wd))` but doesn't work. Any clue will be appreciated.