Compute the mode for each cell across the layers of a SpatRaster. The mode, or modal value, is the most frequent value in a set of values.
# S4 method for SpatRaster modal(x, ..., ties="first", na.rm=FALSE, filename="", overwrite=FALSE, wopt=list())
additional argument of the same type as
x or numeric
character. Indicates how to treat ties. Either "random", "lowest", "highest", "first", or "NA"
NA values are ignored. If
NA is returned if
x has any
character. Output filename
filename is overwritten
list with named options for writing files as in
r <- rast(system.file("ex/logo.tif", package="terra")) r <- c(r/2, r, r*2) m <- modal(r)