Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment: R Programming and Data Analysis

Sales Analysis and Customer Segmentation - Problem and Purpose

Your company wants to understand which products generate the most revenue and identify which customers
are the most valuable based on their purchase patterns. You have been provided with a dataset that includes
information about the sales made over the past year. The company is particularly interested in:

1. The total revenue generated by each product.


2. Identifying high-value customers who purchase the most.
3. Creating a customer segmentation based on spending.

Exo 1: Sales Data Analysis


Task:
1. Data Preparation:

• Load the sales dataset into R and perform basic data exploration to understand its structure.
Purpose: This step helps to understand the data structure, check for missing values, and perform
initial exploration.
2. Revenue Calculation:

• Calculate the total revenue for each product using the formula: Revenue = UnitsSold * PricePe-
rUnit.
Purpose: This step calculates how much revenue each product generates, helping the company
determine which products are performing the best financially.
3. Identify Top Products:

• Sort the products by total revenue in descending order and display the top 5 products.
Purpose: Sorting the data by revenue helps the company quickly identify the top-selling products.
4. Customer Spending:

• Group the data by CustomerID and calculate the total spending for each customer.
Purpose: This step helps identify which customers contribute the most to overall revenue.
5. Customer Segmentation:
• Create a new column to categorize customers based on their total spending: ”Low Value”,
”Medium Value”, ”High Value”.
Purpose: Customer segmentation helps the company focus on different customer groups with targeted
marketing strategies.
6. Visualization:

• Create a bar plot showing the distribution of customers across the three segments.
Purpose: Visualization makes it easy to understand the distribution of customers in each segment.

1
Exo 2: Advanced Sales Insights
Task:

1. Apply Discounts:
• Apply a 10% discount on products that have sold more than 500 units.
Purpose: Simulates business strategies like offering discounts to boost sales.
2. Total Revenue After Discount:

• Recalculate the total revenue after applying the discounts.


Purpose: Allows the company to see how discounts impact overall revenue.
3. Export the Results:

• Save the final dataset into a CSV file for further use.
Purpose: Saving the data allows for further analysis or sharing with other teams.

Exo 3: Additional Analysis


Task:
1. Median Calculation:
• Calculate the median value of the TotalSpending column.

Purpose: The median provides insight into the central tendency of the spending data, helping to
understand typical customer behavior.
2. Cumulative Distribution Function (CDF):
• Calculate and plot the cumulative distribution function (CDF) for the TotalSpending column.

Purpose: The CDF helps visualize the probability that the TotalSpending variable takes a value less
than or equal to a specific amount.
3. Histogram:
• Create a histogram to visualize the distribution of the TotalSpending column.

Purpose: The histogram helps understand the spread and distribution of customer spending.
4. Bar Plot:
• Create a bar plot showing the frequency of products based on different price ranges.
Purpose: The bar plot helps visualize the number of products that fall within specific price ranges,
useful for product pricing strategies.
5. For Loops:
• Write a for loop to iterate over the PricePerUnit column and print the square of each price.
Purpose: This exercise helps practice looping through a dataset and performing operations on each
element.
6. Custom Functions:
• Write a custom function that takes a vector of prices as input and returns the square of each
price.

Purpose: Custom functions in R allow code reuse and modularization, which is essential for handling
repetitive tasks efficiently.

You might also like