rfm: Tools for customer segmentation analysis

Author: Aravind Hebbali
License: MIT

CRAN_Status_Badge Travis-CI Build Status AppVeyor Build Status Coverage Status

In the long run, the goal of rfm is to develop tools for customer segmentation and lifetime value analysis. Included in version 0.0.1 are tools for RFM (recency, frequency and monetary) analysis.


You can install rfm from github with:

Consistent Prefix

rfm uses consistent prefix rfm_ for easy tab completion.



RFM (recency, frequency, monetary) analysis is a behavior based technique used to segment customers by examining their transaction history such as

  • how recently a customer has purchased (recency)
  • how often they purchase (frequency)
  • how much the customer spends (monetary)

It is based on the marketing axiom that 80% of your business comes from 20% of your customers. RFM helps to identify customers who are more likely to respond to promotions by segmenting them into various categories.


To calculate the RFM score for each customer we need transaction data which should include the following:

  • a unique customer id
  • date of transaction/order
  • transaction/order amount

Heat Map

The heat map shows the average monetary value for different categories of recency and frequency scores. Higher scores of frequency and recency are characterized by higher average monetary value as indicated by the darker areas in the heatmap.


Bar Chart

Use rfm_bar_chart() to generate the distribution of monetary scores for the different combinations of frequency and recency scores.



Use rfm_histograms() to examine the relative distribution of

  • monetary value (total revenue generated by each customer)
  • recency days (days since the most recent visit for each customer)
  • frequency (transaction count for each customer)

Customers by Orders

Visualize the distribution of customers across orders.


Scatter Plots

The best customers are those who:

  • bought most recently
  • most often
  • and spend the most

Now let us examine the relationship between the above.

Recency vs Monetary Value


Frequency vs Monetary Value


Recency vs Frequency


Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.