dup_detect: dup_detect

View source: R/dup_detect.R

dup_detectR Documentation

dup_detect

Description

Identifies all duplicated elements in an atomic vector, including "original" duplicated values.

Usage

dup_detect(test, verbose = FALSE)

Arguments

test

An atomic vector.

verbose

TRUE/FALSE indicating whether detailed output should be printed to the console.

Details

dup_detect() is different than base::duplicated(). If you passed c(5, 5, 7) to duplicated(), the function would identify one duplicated value (the second 5). But we often want to identify all matching values in a vector of value (i.e., flag both 5 values in the vector above as duplicates, not just the second one). dup_detect() does that.

dup_detect() will:

  • Return a logical vector (invisibly) indicating which elements are duplicated (including "original" duplicates)

  • Optionally, tell you the total number of duplicated values in a vector and the number of duplicate vector elements for each duplicated value (verbose argument)

Value

  • Console output with information on duplicates (verbose = TRUE|FALSE).

  • A logical vector indicating which vector elements are duplicates (including "original" duplicates).

Examples

# Create 20 IPv4 addresses and use dup_detect on them:
set.seed(4)
ip_addresses <- replicate(20, paste0(sample(0:255, 4, replace = TRUE), collapse = "."))
duplicate <- sample(seq_along(ip_addresses), size = 3)
ip_addresses[duplicate + 1] <- ip_addresses[duplicate]
dup_detect(ip_addresses, verbose = TRUE)


jacob-gg/manager documentation built on July 2, 2024, 2:09 a.m.