I have an Orders database for an online shopping platform.
The table I'm working with looks like this, where each line corresponds to one customer/item/date.
OrderHistory <- data.frame(date=c("2015-02-01", "2015-03-01", "2015-04-01", "2015-03-01", "2015-04-01", "2015-05-01", "2015-05-01"),
customer=c("A","A","A","B","B","B","B"),
item=c("Candy", "Coffee", "Coffee", "Candy", "Candy", "Candy", "Coffee" ))
What I would like to get is a running count of the number of times each member has ordered the specific item so I can run analysis on which items are ordered repeatedly by the same customers and which ones are ordered once and never again.
The output would look like
out <- data.frame(date=c("2015-02-01", "2015-03-01", "2015-04-01", "2015-03-01", "2015-04-01", "2015-05-01", "2015-05-01"),
member=c("A","A","A","B","B","B","B"),
item=c("Candy", "Coffee", "Coffee", "Candy", "Candy", "Candy", "Coffee" ),
count=c(1,1,2,1,2,3,1))
I would love a dplyr solution but I'm open to any suggestions! The exact items on the platform are constantly changing, so the solution would have to be dynamic to account for that.