sort | R Documentation |
Sort the cell values of a SpatRaster across layers. You can also compute the sorting order.
Or sort the records of SpatVector (or data.frame) by specifying the column number(s) or names(s) to sort on.
## S4 method for signature 'SpatRaster'
sort(x, decreasing=FALSE, order=FALSE, filename="", ...)
## S4 method for signature 'SpatVector'
sort(x, v, decreasing=FALSE)
x |
SpatRaster |
decreasing |
logical. If |
order |
logical. If |
filename |
character. Output filename |
... |
additional arguments for writing files as in |
v |
character or numeric indicating the column(s) to sort on |
SpatRaster
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
r <- c(r, r/2, r*2)
sort(r)
ord <- sort(r, order=TRUE)
# these two are the same
ord[[1]]
which.min(r)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.