I am calculating the percentage of the impact within multiple rasters. I have one raster with a sum of whole variables (SUM). Then I have 9 rasters that I want to loop and calculate the percentage of the impact (Variables). I am using the function because I will use different inputs. When the function stops I want to have a text file or whatever is possible to export. I tried using rbind() but it does not work it is always empty when the function is executed. Here is the code:
Var_Sum_Impact(EU_HS_45_2041_SUM.r[[1]], EU_HS_45_2041_Var_Medi_Steppic.r)
results = data.frame(col1=numeric(), stringsAsFactors=FALSE)
Var_Sum_Impact = function(SUM, Variables) {
for (i in 1:9){
Var = cellStats(Variables[[i]], stat='mean')
Su = cellStats(SUM, stat='mean')
Perc = Var/(Su/100)
print(Perc)
results = rbind(results, Perc)
}
}
And here is the result I get from that print but "results" is empty (0 obs.). The calculation is correct:
[1] 9.418741
[1] 20.39071
[1] 12.96036
[1] 5.910591
[1] 4.998413
[1] 21.37485
[1] 6.379199
[1] 4.383655
[1] 14.18348
results$col1[i] <- Perc