The native duplicated function determines which elements of a vector
or data frame are duplicates of elements already observed in the vector or the
data frame provided. Therefore, only the second occurence (or third or nth)
of an element is considered as a duplicate.
duplicated2
is similar but will also mark the first occurence as a
duplicate (see examples).
duplicated2(x)
a vector, a data frame or a matrix
A logical vector indicated wich elements are duplicated in x
.
df <- data.frame(x = c("a", "b", "c", "b", "d", "c"), y = c(1, 2, 3, 2, 4, 3))
df
#> x y
#> 1 a 1
#> 2 b 2
#> 3 c 3
#> 4 b 2
#> 5 d 4
#> 6 c 3
duplicated(df)
#> [1] FALSE FALSE FALSE TRUE FALSE TRUE
duplicated2(df)
#> [1] FALSE TRUE TRUE TRUE FALSE TRUE