3
votes

I have hundreds of rasters with same resolution and extent. It's a time series and each raster represent one point of time.

I know how to find the absolute maximum value in a raster.

But how can I find the maximum value in each cell in the entire time series of rasters?

If a1,a2,......a1000 are rasters, I want to create a raster x where each pixel is the maximum of all corresponding pixels of a1-a1000.

1
Look at ?pmax. Try for instance pmax(a1[],a2[],...) where a1, a2 and so on are your raster objects.nicola

1 Answers

4
votes

If you first put the rasters in a stack, you can then simply apply min() or max() to the stack to get the summary RasterLayer you're after

## Example rasters and stack
r1 <- raster(matrix(1:4,ncol=4))
r2 <- -2*r1
r3 <- 2*r1
rr <- list(r1,r2,r3)
s <- stack(rr)

## Extract the pixel-wise min and max values
min(s)
max(s)

(To apply some other, more complicated function that returns a scalar for each pixel in the stack, you may want to use calc(), as demonstrated (for example) here.)