Self Joins in R
Sometime back at work, I was faced with a dilemma. I am one of those people who might get stuck on something because I have a "feeling" there is a shorter way to do it. Neither am I the biggest fan of writing several lines of code when there is an option to have less lines. I know that my tendency towards less lines of code sometimes is not the best bacause it might hinder readability. To explain my dilemma, I have created a sample data frame as follows Code: data <-data.frame( ID = c(12,12,34,36,47,47,58,68,77,77), Call_Duration = c(20,20,25,27,40,40,50,55,20,20), Call_Reason = c("Reason 1", "Reason 2", "Reason 3", "Reason 1","Reason 3", "Reason 6", "Reason 4", "Reason 1", "Reason 2", "Reason 3") ) Running the code above results to the below dataframe The Dilemma How can I easily find and count duplicate IDs so that I can ration call duration to...