How to find maximum value in rasterbrick?

1.2k views Asked by At

I know there is a similar question but it is not in rasterbrick. I would like to find the maximum value in this raster brick, I tried which.max but I don't understand the input. I would like to know what is the maximum value, and also get a list of all the maximum values for each layer.

> bshum2
class       : RasterBrick 
dimensions  : 5, 4, 20, 2920  (nrow, ncol, ncell, nlayers)
resolution  : 1, 1  (x, y)
extent      : 14, 18, 0, 5  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : X1979.01.01.00.00.00, X1979.01.01.03.00.00, 
min values  :          0.011909009,          0.011799878,          
max values  :           0.01536649,          0.01594792,           time        : 1979-01-01 00:00:00, 1979-12-31 21:00:00 (min, max)

> which.max(bshum2)
class       : RasterLayer 
dimensions  : 5, 4, 20  (nrow, ncol, ncell)
resolution  : 1, 1  (x, y)
extent      : 14, 18, 0, 5  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
data source : in memory
names       : layer 
values      : 172, 1132  (min, max)
1

There are 1 answers

2
Robert Hijmans On BEST ANSWER

This is how you can get these:

library(raster)
b <- brick(system.file("external/rlogo.grd", package="raster"))
minValue(b)
# [1] 0 0 0
maxValue(b)
# [1] 255 255 255