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

modal

modal value


Description

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.

Usage

## S4 method for signature 'SpatRaster'
modal(x, ..., ties="first", na.rm=FALSE, filename="", overwrite=FALSE, wopt=list())

Arguments

x

SpatRaster

...

additional argument of the same type as x or numeric

ties

character. Indicates how to treat ties. Either "random", "lowest", "highest", "first", or "NA"

na.rm

logical. If TRUE, NA values are ignored. If FALSE, NA is returned if x has any NA values

filename

character. Output filename

overwrite

logical. If TRUE, filename is overwritten

wopt

list with named options for writing files as in writeRaster

Value

SpatRaster

Examples

r <- rast(system.file("ex/logo.tif", package="terra"))   
r <- c(r/2, r, r*2)
m <- modal(r)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

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