Skip to main content
deleted 37 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

R: Replace Replacing raster values with the closest value from a list using R?

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.

R: Replace raster values with the closest value from a list

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.

Replacing raster values with closest value from list using R?

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.

Source Link

R: Replace raster values with the closest value from a list

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.