I want to multiply two rasters in R with 'terra'. Raster1 has 457 bands with EVI values meanwhile raster2 is a one-layer raster -of almost same extent- with binary values (0 or 1). The result that I want to achieve is to get raster1 (with the 457 original bands) with values only in pixels that has a value = 1 in raster2. That's why I want to multiply them.
I have tried:
result <- raster1 * raster2
result <- overlay(raster1, raster2, fun = function(x,y){return(x*y)}, unstack=FALSE)
But it doesn't work. I appreciate some help.