Returns the minimum or maximum value of a RasterLayer or layer in a RasterStack

minValue(x, ...)
maxValue(x, ...)

Arguments

x

RasterLayer or RasterStack object

...

Additional argument: layer number (for RasterStack or RasterBrick objects)

Value

a number

Details

If a Raster* object is created from a file on disk, the min and max values are often not known (depending on the file format). You can use setMinMax to set them in the Raster* object.

Examples

r <- raster()
r <- setValues(r, 1:ncell(r))
minValue(r)
#> [1] 1
maxValue(r)
#> [1] 64800
r <- setValues(r, round(100 * runif(ncell(r)) + 0.5))
minValue(r)
#> [1] 1
maxValue(r)
#> [1] 100

r <- raster(system.file("external/test.grd", package="raster"))
minValue(r)
#> [1] 138.7071
maxValue(r)
#> [1] 1736.058