Q:

Match objects with same IDs except for one

I have a dataframe with the following format:
df <- data.frame(DS.ID=c(123,214,543,325,123,214),
                 P.ID=c("AAC","JGK","DIF","ADL","AAE","JGK"),
                 OP.ID=c("xxab","xxac","xxad","xxae","xxab","xxac"))

   DS.ID   P.ID OP.ID
1   123    AAC  xxab
2   214    JGK  xxac
3   543    DIF  xxad
4   325    ADL  xxae
5   123    AAE  xxab
6   214    JGK  xxac

I'm trying to find instances where DS.ID is equal to another DS.ID, OP.ID is equal to another OP.ID, but the P.ID's are not equal.  I know how to do it with a loop but I'd rather do a quicker method so it returns the DS.ID's/information of those that do not match.  Either with a logical vector in another column or through the DS.ID's. 

A:

Using duplicated:
df$match <- duplicated(df$DS.ID,df$OP.ID,fromLast=TRUE) | 
            duplicated(df$DS.ID,df$OP.ID)
# df
# DS.ID P.ID OP.ID match
# 1   123  AAC  xxab  TRUE
# 2   214  JGK  xxac  TRUE
# 3   543  DIF  xxad FALSE
# 4   325  ADL  xxab FALSE
# 5   123  AAE  xxab  TRUE
# 6   214  JGK  xxac  TRUE

EDIT after OP clarification 
dupli.2 <- duplicated(df$DS.ID,df$OP.ID,fromLast=TRUE) |  duplicated(df$DS.ID,df$OP.ID)
dupli.all <-  duplicated(df) | duplicated(df,fromLast=TRUE)
as.logical(dupli.2 - dupli.all)
[1]  TRUE FALSE FALSE FALSE  TRUE FALSE

