RFM Analysis (Recency, Frequency and Monetary)

RFM is frequently employed in customer analytics and tools like SPSS have built in functions to perform it. This repository is an effort to make a similar package for R.

Sample data set : "sales" Fictional dataset containing customer names, date of purchase and amount of purchase.

library(RFM)
head(sales)

Perform simple RFM analysis on the data

rfm(sales)

By default, Recency is calculated from the current date. This behaviour can be altered by specifying Analysis date.

#RFM with analysis date as 20th of Jan 2016
rfm(sales,analysisDate = "2016/01/20")

Note the dates have to be in "yyyy/mm/dd" format. eg : 2016/12/23.

By default, the function looks for "customer", "date" and "amount" columns.

Custom column names may be specified:

#Creating  sales data  set with customer, billDate and revenue as column names
newsales = sales
names(newsales) = c("customer", "billDate", "revenue")
rfm(newsales,analysisDate = "2016/01/20", customer = "customer", date = "billDate", revenue = "revenue")

Installation

#Uncomment block below
#install.packages("devtools")
#library(devtools)
#install_github("astrosyam/RFM")

Disclaimer: This is an initial commit and is therefore limited to basic RFM. The code is currently not optimized or bug free.

Wishlist

Future commits will add the following functionalities:

  1. Custom weightage of components, for eg. MFR, where Monetary has a higher preference than Recency while scoring.

  2. Specify custom bins for scoring

  3. Customer purchase latency



astrosyam/RFM documentation built on May 10, 2019, 2:05 p.m.