Q:

Understanding R's anyDuplicated

Quick question in understanding's R's anyDuplicated, when passed on a dataframe (lets say x y z columns with 1k observations) will if check if any of the rows has the exact same x y z values as another row in the same dataframe? Thanks

A:

I would use duplicated and combine it from front to back.
mydf <- data.frame(x = c(1:3,1,1), y = c(3:5,3,3))
mydf
#   x y
# 1 1 3
# 2 2 4
# 3 3 5
# 4 1 3
# 5 1 3

There three duplicated rows 1, 4, and 5. But 'duplicated' will only mark what is duplicated not the original value also.
duplicated(mydf)
#[1] FALSE FALSE FALSE  TRUE  TRUE
duplicated(mydf, fromLast = TRUE)
#[1]  TRUE FALSE FALSE  TRUE FALSE

Using from last looks from the end to front to include the original value. By the way, I will ask the R core team to add a unified function to do both.
myduplicates <- duplicated(mydf) | duplicated(mydf, fromLast = TRUE)

Saving the expression as a variable allows us to count and subset later.
sum(myduplicates)
#[1] 3
mydf[myduplicates,]
#   x y
# 1 1 3
# 4 1 3
# 5 1 3
mydf[!myduplicates,]
#   x y
# 2 2 4
# 3 3 5

