I have a function that I wrote that looks like this when calling:
myfunction<-(filename_1980, March1980raster.RData, April1980raster.RData, May1980raster.RData, Linkwheretosave="data/filename_1980.RData")
I want to call this function 36 times, but each time change the year so that it is called for each year between 1980-2015.
So instead of calling the function 36 times and manually changing the year in each filename, is there a way to put this into a for loop so that the names get automatically changed with each following year?
For example, I would want the first iteration to run exactly as above, but the next iteration to run as:
myfunction<-(filename_1981, March1981raster.RData, April1981raster.RData, May1981raster.RData, Linkwheretosave="data/filename_1981.RData")
and continue just changing the year until 2015 is reached.
My original function (if it's helpful) is written as :
myfunction<- function(filename_year, Marraster, Aprraster, Mayraster, link){
filename_year<-do.call(c, list(Marraster, Aprraster, Mayraster))
filename_year<- list(Reduce(`+`, filename_year) / length(filename_year))
save(filename_year, file= here(link))
}
How can I do this in R?