dup_detect | R Documentation |
Identifies all duplicated elements in an atomic vector, including "original" duplicated values.
dup_detect(test, verbose = FALSE)
test |
An atomic vector. |
verbose |
|
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)
Console output with information on duplicates (verbose = TRUE|FALSE
).
A logical vector indicating which vector elements are duplicates (including "original" duplicates).
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.