1
2setMethod("selectHighest", signature(x="SpatRaster"),
3	function(x, n, low=FALSE) {
4		x <- x[[1]]
5		n <- min(ncell(x), max(1, n))
6		i <- order(values(x, mat=FALSE), decreasing=!low)[1:n]
7		x <- rast(x)
8		x[i] <- 1
9		x
10	}
11)
12
13