Customer Segmentation in R: RFM, Clustering and Actionable Profiles
Learn how to create customer segments in R using RFM features, scaling, clustering, validation and interpretable business profiles.
Customer segmentation groups people with similar behaviour so communication, service or product decisions can be more relevant. Clustering is not useful merely because software can produce several coloured groups; the segments must be stable, interpretable and actionable.
This guide uses RFM and behavioural features as a practical starting point.
What you will learn
- Create one row per customer.
- Choose features linked to decisions.
- Scale variables before distance-based clustering.
- Use several diagnostics to choose cluster count.
- Profile and test actions for every segment.
1. Define the segmentation purpose
A retention segmentation may prioritise recency and declining activity, while a product-personalisation segmentation may need category preferences. Define the decision before selecting variables.
Exclude protected or sensitive attributes unless their use is lawful, ethical and necessary.
2. Build customer-level features
- Recency: time since the most recent transaction.
- Frequency: number of transactions in a stated period.
- Monetary value: spend or margin in that period.
- Breadth: number of product categories used.
- Returns, discounts or channel mix where relevant.
3. Transform and scale
RFM measures are often skewed. Consider log transformations, winsorisation with justification or robust scaling. Standardisation is important because k-means is distance-based and variables with larger numerical ranges otherwise dominate.
Document how customers with no purchases or extreme values are handled.
4. Select and validate clusters
- Elbow plot for within-cluster variation.
- Silhouette width for separation.
- Stability across seeds or resamples.
- Cluster sizes that are operationally usable.
- Interpretability against the original variables.
5. Create segment profiles
Describe each cluster using medians, distributions and business-relevant outcomes. Avoid labels that stereotype people. A useful label reflects observed behaviour, such as recent high-frequency customers or lapsed low-frequency customers.
Visualise profiles without implying that all members are identical.
6. Test segment actions
Assign a proposed action, cost and outcome to each segment. Measure incremental results through experiments or suitable comparison groups. Recalculate segments periodically because behaviour changes.
Clustering itself does not prove that different campaigns will work.
NEED HELP WITH YOUR ASSIGNMENT?
Submit your assignment instructions for private support.
Frequently asked questions
Why must variables be scaled for k-means?
K-means uses distances. A variable measured on a much larger scale can dominate the clustering even when it is not more important.
How many clusters should be used?
There is no single automatic answer. Combine statistical diagnostics, stability, interpretability and operational usefulness.
Is RFM enough for every segmentation?
No. It is a useful behavioural baseline, but the feature set should match the business decision.
Can cluster labels be used permanently?
Customer behaviour changes, so segment memberships and definitions should be monitored and refreshed.