Skip to content

Regional Average of Rasters

1 message · Tiffany Smith

#
I have a rasterBrick (temp) with global temperatures, and a rasterLayer (regions) of global regions. I would like to create a rasterBrick of regional average temperatures. So far I have the following:

region1<-mask(temp,regions,maskvalue=1,inverse=TRUE)
mean1<-cellStats(region1,mean)

region2<-mask(temp,regions,maskvalue=2,inverse=TRUE)
mean2<-cellStats(region2,mean)

At which point, I?m not sure how to get this back into raster format. Alternatively, this can?t be the most efficient way to do this - any ideas would be much appreciated.

Thanks,
Tiffany