[Data structure][1]I have a series of raster files which correspond to species biomass distribution per year. I am trying to take the mean of the first 5 years per each species. So far I managed to do as the code below. what the code does is to make the mean for all the years of that species. Instead i want to have the mean for the first 5 years. In the figure you see that years go from 12 to 264 so essentially the mean should be from 12 to 60 per each species
Any idea, tips?
all_files <- list.files(files_path,full.names = TRUE,pattern = ".asc$")
species = gsub("-.*.asc","",gsub(".*mass-","",all_files))
files_stack <- stack(all_files)
means = stackApply(files_stack, indices=species, fun=mean)
[1]: https://i.stack.imgur.com/s7LyK.png