distinct.SpatVector {tidyterra} | R Documentation |
Keep distinct/unique rows and geometries of SpatVector
objects
Description
Keep only unique/distinct rows and geometries from a SpatVector
.
Usage
## S3 method for class 'SpatVector'
distinct(.data, ..., .keep_all = FALSE)
Arguments
.data |
A |
... |
< |
.keep_all |
If |
Value
A SpatVector
object.
terra equivalent
Methods
Implementation of the generic dplyr::distinct()
function.
SpatVector
It is possible to remove duplicate geometries including the geometry
variable explicitly in the ...
call. See Examples.
See Also
dplyr::distinct()
, terra::unique()
Other dplyr verbs that operate on rows:
arrange.SpatVector()
,
filter.Spat
,
slice.Spat
Other dplyr methods:
arrange.SpatVector()
,
bind_cols.SpatVector
,
bind_rows.SpatVector
,
count.SpatVector()
,
filter-joins.SpatVector
,
filter.Spat
,
glimpse.Spat
,
group-by.SpatVector
,
mutate-joins.SpatVector
,
mutate.Spat
,
pull.Spat
,
relocate.Spat
,
rename.Spat
,
rowwise.SpatVector()
,
select.Spat
,
slice.Spat
,
summarise.SpatVector()
Examples
library(terra)
v <- vect(system.file("ex/lux.shp", package = "terra"))
# Create a vector with dups
v <- v[sample(seq_len(nrow(v)), 100, replace = TRUE), ]
v$gr <- sample(LETTERS[1:3], 100, replace = TRUE)
# All duplicates
ex1 <- distinct(v)
ex1
nrow(ex1)
# Duplicates by NAME_1
ex2 <- distinct(v, gr)
ex2
nrow(ex2)
# Same but keeping all cols
ex2b <- distinct(v, gr, .keep_all = TRUE)
ex2b
nrow(ex2b)
# Unique geometries
ex3 <- distinct(v, geometry)
ex3
nrow(ex3)
# Same as terra::unique()
terra::unique(ex3)
# Unique keeping info
distinct(v, geometry, .keep_all = TRUE)