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

unique

Unique values


Description

This function returns the unique values in a SpatRaster or removes duplicates in a SpatVector.

Usage

## S4 method for signature 'SpatRaster'
unique(x, incomparables=FALSE) 

## S4 method for signature 'SpatVector'
unique(x, incomparables=FALSE, ...)

Arguments

x

SpatRaster or SpatVector

incomparables

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

...

additional arguments passed on to base::unique

Value

If x is a SpatRaster: vector or matrix

If x is a SpatVector: SpatVector

Examples

r <- rast(ncol=5, nrow=5)
values(r) <- rep(1:5, each=5)
unique(r)
s <- c(r, round(r/3))
unique(s)
unique(s,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)

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.