Data example:
library(dplyr)
df1 <- data.frame(
ID = c(1,2,2,3,4,4,5,6,6,8,9,33,32,33,33,22,22,22,23,23),
product= c("A", "B", "B", "A", "C", "D", "C", "A", "F", "A",
"C", "P", "R", "Q", "W", "A", "B","B", "D", "D"))
The Problem:
1) If the "ID"" and the "product"" features has a "product" type that is different within the same "ID", then exclude those observations. For example "ID": 4, 4 and "product": C, D
2) If the "ID" and the "product" features have the same repeated value, then leave those observations. For example "ID": 2, 2 and "product": B, B.
3) If the "ID"" and the "product"" have only one observation, then leave that observation in the data frame. For example "ID": A and "product": 1.
What I have tried:
df1 %>%
group_by(ID, product) %>%
filter(n() > 1)
Expected Result
ID product
1 A
2 B
2 B
3 A
5 C
8 A
9 C
32 R
23 D
23 D