Data:
DB1 <- data.frame(orderItemID = c(1,2,3,4,5,6,7,8,9,10),
orderDate = c("1.1.12","1.1.12","1.1.12","1.1.12","1.1.12", "1.1.12","1.1.12","1.1.12","2.1.12","2.1.12"),
itemID = c(2,3,2,5,12,4,2,3,1,5),
size = factor(c("l", "s", "xl", "xs","m", "s", "l", "m", "xxs", "xxl")),
color = factor(c("blue", "black", "blue", "orange", "red", "navy", "red", "purple", "white", "black")),
customerID = c(33, 15, 1, 33, 14, 55, 33, 78, 94, 23))
Expected output:
selection_order = c("yes","no","no","no","no","no","yes","no","no","no")
In the data set I have items with the same size or the same color, the same ItemID. Every registered user has his unique customerID.
I want to identify when a user orders products (more then one) with the same itemID (in different sizes or colors = for example the user with the customerID = 33
orders the same item (ItemID = 2
) in two different colors) and mark it in a new column named like "selection order"(for example) with "Yes" or "No". It should NOT show me a "Yes", when he or she orders an item with an other ID. I just want to get a "yes", when there is an order (at the same day or in the past) with the same ID more then once - regardless from other ID´s (other products).
I've tried a lot already,but nothing works. There are a few thousand different userID's and ItemId's-so I can´t subset for every Id. I tried it with the duplicated function - but it's not leading to a satisfactory solution:
The problem is, that if the same person orders more then one object (customerID is duplicated then) and another person(customerId) orders an item with the same Id (itemId is duplicated then) it gives me a "yes": and it must be a "No" in this case. (in the example the duplicate function will give me an "yes" at orderItemID 4 instead of an "no")