Here’s an example:
df <- data.frame(a = c(1,2,3,4,1,5,6,4,2,1))
duplicated(df) | duplicated(df, fromLast = TRUE)
#[1] TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE TRUE TRUE
How it works?
The function duplicated(df) determines duplicate elements in the original data. The fromLast = TRUE indicates that “duplication should be considered from the reverse side”. The two resulting logical vectors are combined using | since a TRUE in at least one of them indicates a duplicated value.