March 2019
Beginner to intermediate
464 pages
10h 57m
English
In order to calculate the CLV, we need to know the frequency, recency, and total amount of purchases by each customer. We are going to compute basic information about each customer's average and lifetime purchase amount, as well as each customer's duration and frequency of purchases. Take a look at the following code:
# order amount & frequency summarysummaryDF <- ordersDF %>% group_by(CustomerID) %>% summarize( SalesMin=min(Sales), SalesMax=max(Sales), SalesSum=sum(Sales), SalesAvg=mean(Sales), SalesCount=n(), InvoiceDateMin=min(InvoiceDate), InvoiceDateMax=max(InvoiceDate), PurchaseDuration=as.double(floor(max(InvoiceDate)-min(InvoiceDate))), PurchaseFrequency=as.double(floor(max(InvoiceDate)-min(InvoiceDate)))/n() )
We ...
Read now
Unlock full access