I want to create a function that will give a new dataframe only with rows in which for the selected column the value is counted exactly 2 times in the original data.frame
I try this:
duplicates <- function(df$x, as.bool = TRUE) {
is.dup <- (duplicated(x) & rev(duplicated(rev(x))))
if (as.bool) { is.dup } else { x[is.dup] }
}