mardi 10 novembre 2020

Multiple if-else for raster data in R

I have two raster as follows

library(raster)

a <- brick(ncol=100, nrow=100, nl=1)
set.seed(2)     
values(a) = runif(10000, min=-1, max=1)    # define the range between -1 and 1

b <- brick(ncol=100, nrow=100, nl=1)
set.seed(2)     
values(b) = runif(10000, min=25, max=35)

Now I want to create a new raster based on multiple conditions. The conditions are like

when a = 0 - 0.2, the new raster pixels should have the values of 1.5;

when a > 0.5, the new raster pixels should have the values of 1.85;

when 0.2 <= a <= 0.5, the new raster pixels should have the values of 1.70.

How to implement it in R?

Aucun commentaire:

Enregistrer un commentaire