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)
Run the code above in your browser using DataLab