This method returns the unique values in a SpatRaster, or removes duplicates records (geometry and attributes) in a SpatVector.
# S4 method for SpatRaster
unique(x, incomparables=FALSE, digits=NA, na.rm=TRUE, as.raster=FALSE) # S4 method for SpatVector
unique(x, incomparables=FALSE, ...)
If x
is a SpatRaster: data.frame or list (if incomparables=FALSE
)
If x
is a SpatVector: SpatVector
SpatRaster or SpatVector
logical. If FALSE
and x
is a SpatRaster: the unique values are determined for all layers together, and the result is a matrix. If TRUE
, each layer is evaluated separately, and a list is returned. If x
is a SpatVector this argument is as for a data.frame
integer. The number of digits for rounding the values before finding the unique values. Use NA
means to not do any rounding
logical. If TRUE
, NaN
is included if there are any missing values
logical. If TRUE
, a single-layer categorical SpatRaster with the unique values is returned
additional arguments passed on to unique
r <- rast(ncols=5, nrows=5)
values(r) <- rep(1:5, each=5)
unique(r)
s <- c(r, round(r/3))
unique(s)
unique(s,TRUE)
unique(s, as.raster=TRUE)
v <- vect(cbind(x=c(1:5,1:5), y=c(5:1,5:1)),
crs="+proj=utm +zone=1 +datum=WGS84")
nrow(v)
u <- unique(v)
nrow(u)
values(v) <- c(1:5, 1:3, 5:4)
unique(v)
Run the code above in your browser using DataLab