This is the function that I want to create:
Erosivity_Factor = 1.74 * log[sum(montly²/annual)]+1.29
I have solved it using a loop:
# Reproducible RasterStack with 12 layers
Monlty<- stack(lapply(1:12, function(i) raster(ncol=20, nrow=20, vals=rnorm(400,30))))
# Reproducible Raster
Annual <- raster(ncol=20, nrow=20, vals=rnorm(400,230))
R_month<- list()
for (i in 1:12) {
R_month[[i]]<- (Monlty[[i]]*Monlty[[i]]/Annual)
}
R_month_raster <- do.call(stack,R_month)
R_erosivity_factor<- (1.74*log10(calc(R_month_raster,sum))+1.29)
Is there a way to make it with a function?