here is my Dataset
customer_id | partner_id | category | location |
---|---|---|---|
AAP | AAS | 3 | Melbourne |
AAP | AAS | 1 | Silicon Valley |
AAP | AAS | 1 | Sydney |
AAP | AAS | 2 | Sydney |
AAP | AAD | 1 | Sydney |
AAP | AAD | 3 | Sydney |
AMS | ADP | 3 | New York |
AMS | ADP | 1 | New York |
AMS | AXP | 2 | Dallas |
AMS | AXP | 1 | Dallas |
Combination = Customer+Partner+location
i would like to summarize based on
if combination & Category == 1
replace category 1 with the biggest number
if the big Category number in combination is 3 replace category with 3 for all same Combination contain 1
if the big number is 2 replace with 2
else case let it be 1 as is.
how to do Self Join in R.?
you can execute the below R Snippet to get the data in R Console
customer_id<-c("AAP", "AAP", "AAP", "AAP", "AAP", "AAP", "AMS", "AMS", "AMS", "AMS")
partner_id<-c("AAS", "AAS", "AAS", "AAS", "AAD", "AAD", "ADP", "ADP", "AXP", "AXP")
category<-c(3,1,1,2,1,3,3,1,2,1)
location<-c("Melbourne", "Silicon Valley", "Sydney", "Sydney", "Sydney", "Sydney", "New York", "New York", "Dallas", "Dallas")
dataset<- data.frame(customer_id, partner_id, category,location)