Dear list,
I can't find a solution to this problem:
Let's say I have a map of water depth due to a flood , and the corresponding land-use:

library(raster)
WaterDepth<-raster(matrix(1:20, nrow = 5, ncol = 4))
LandUse<-raster(WaterDepth)
LandUse[]<-c(rep(1,12),rep(2,8))

# each land use class has a different relation between water depth and damage, which is defined per points and that I can interpolate linearly:
Damage<-data.frame(V1=c(0,100,150,230,340,340),V2=c(0,55,120,160,225,225))
Depths<-c(0,0.5,1,2,4,100)     #Water depth in meters
DDFun<-lapply(Damage, approxfun, x=Depths)

# Now if I want to know the estimated cost of the damage on a specific grid point it seems to work:
i<-3
Cost<-raster(WaterDepth)
Cost[i] <- DDFun[[LandUse[i]]](WaterDepth[i])

> Cost[i]
    
340 


But it doesn't work if I try to apply it to the entire map extent:

> Cost[] <- DDFun[[LandUse[]]](WaterDepth[])
Error in DDFun[[LandUse[]]] : recursive indexing failed at level 2

Any suggestion on how to do this (possibly without looping on each land use class)?

Thanks

Lorenzo
 		 	   		  
	[[alternative HTML version deleted]]

