Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

which.minmax

Where is the min or max value?


Description

Which cells have the minumum / maximum value (for a RasterLayer), or which layer has the minimum/maximum value (for a RasterStack or RasterBrick)?

which.min and which.max return the index of the first layer that has the min or max value for a cell. This can be problematic if there are ties.

In you want the index of all the layers that have the min or max value, use whiches.min or whiches.max (only for objects with less than 10 layers).

Usage

which.min(x)
which.max(x)
whiches.min(x, ...)
whiches.max(x, ...)

Arguments

x

Raster* object

...

additional arguments (none implemented)

Value

(which.*): vector of cell numbers (if x is a RasterLayer). If x is a RasterStack or RasterBrick, a RasterLayer giving the number of the first layer with the minimum or maximum value for a cell.

(whiches.*). An integer in which each digit represents a layer. For example, 35 means "layers 3 and 5"

Note

There is a limit to accurate integer number representation. Therefore, do not use whiches.* with more than 15 layers.

See Also

Examples

b <- brick(system.file("external/rlogo.grd", package="raster")) 

r <- which.min(b)

i <- which.min(b[[3]])
xy <- xyFromCell(b, i)
plot(b[[3]])
points(xy)

x <- whiches.min(b)
freq(x)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.