I am looking to generate a unique ID based on identical values in either of two columns. Specifically, I have the phone numbers and e-mails of customers over a historic period. Therefore, I want to generate a unique ID identifying the customer, even if the customer has changed phone number or e-mail during this time period. The data looks like this:
E-mail Phone Name
mortena 3076 morten
kaspera 2688 kasper
christoffera 1212 christoffer
mortenb 3076 morten
mortena 3075 morten
kasperb 2688 kasper
christoffera 1213 christoffer
And I'd like to produce this result:
E-mail Phone Name ID
mortena 3076 morten 1
kaspera 2688 kasper 2
christoffera 1212 christoffer 3
mortenb 3076 morten 1
mortena 3075 morten 1
kasperb 2688 kasper 2
christoffera 1213 christoffer 3
Any help is much appreciated!
I've attempted to utilize the code below. However, this seems to create ID's based on identical e-mail and phonenumbers. I am looking to generate a unique ID based on either e-mail or phonenumber.
test_data %>%
mutate(ID = group_indices_(test_data, .dots=c("E.mail", "Phone")))
I expect the script to check through phone numbers and generate a unique ID per unique phone number, and if it can't find any duplicate phone numbers then go through e-mail and do the same thing.