Lot's of questions out there touching the topic of duplicate observations but none of them worked for me so far.
In this questions I learned how to select all duplicates from a vector.
# vector
id <- c("a","b","b","c","c","c","d","d","d","d")
#To return ALL duplicated values by specifying fromLast argument:
id[duplicated(id) | duplicated(id, fromLast=TRUE)]
## [1] "b" "b" "c" "c" "c" "d" "d" "d" "d"
#Yet another way to return ALL duplicated values, using %in% operator:
id[id %in% unique(id[duplicated(id)])]
## [1] "b" "b" "c" "c" "c" "d" "d" "d" "d"
Now having a data frame like this one:
dat <- data.frame(x = c(1, 1, 2, 2, 3),
y = c(5, 5, 6, 7, 8),
z = c('a', 'b', 'c', 'd', 'e'))
How could I select all observations that simultaneously have duplicate values of x and y, irrespective of z?