VIPSolutions logo ✨ VIPSolutions

Question You work as a data analyst for an e-commerce company, and your team has collected data on customer transactions. The data is in the form of a data frame with the following colunms: Customer_ID, Purchase Date, Product_Category, and Purchase Amount. Write a function find_repeat_customers that takes the customer transaction data frame as input and retums a vector of customer IDs who have made purchases on more than one occasion In other words, you need to identify customers who have made purchases on at least two different dates. Input: # Sanple customer transaction data frame customer_data

Question:

Uploaded ImageQuestion You work as a data analyst for an e-commerce company, and your team has collected data on customer transactions. The data is in the form of a data frame with the following colunms: Customer_ID, Purchase Date, Product_Category, and Purchase Amount. Write a function find_repeat_customers that takes the customer transaction data frame as input and retums a vector of customer IDs who have made purchases on more than one occasion In other words, you need to identify customers who have made purchases on at least two different dates. Input: # Sanple customer transaction data frame customer_data

This is AI generated Response.
Asked by: KATHI SAIKUMAR
Created at: 2025-09-27 13:17:02

Final Answer:

Rendered Raw Text
Did you like this answer?
## Solution We need to write an R function `find_repeat_customers` that returns customer IDs who made purchases on more than one unique date. ### Step-by-Step 1. **Group by Customer_ID and count unique Purchase_Date for each.** 2. **Select Customer_IDs with count >= 2.** 3. **Return these IDs as a vector.** Here is the code: ```r find_repeat_customers <- function(df) { # Count unique purchase dates for each customer repeat_counts <- aggregate(Purchase_Date ~ Customer_ID, df, function(x) length(unique(x))) # Select customers with more than one purchase date repeat_customers <- repeat_counts$Customer_ID[repeat_counts$Purchase_Date >= 2] return(repeat_customers) } # Sample customer transaction data frame customer_data <- data.frame( Customer_ID = c(101, 102, 103, 101, 104, 102, 105, 101), Purchase_Date = as.Date(c("2023-01-10", "2023-01-15", "2023-01-20", "2023-02-05", "2023-02-10", "2023-02-15", "2023-03-01", "2023-03-05")), Product_Category = c("Electronics", "Clothing", "Electronics", "Books", "Electronics", "Clothing", "Electronics", "Books"), Purchase_Amount = c(500, 300, 450, 200, 550, 250, 600, 150) ) # Find repeat customers repeat_customers <- find_repeat_customers(customer_data) print(repeat_customers) ``` ### **Expected Output** ``` [1] 101 102 ``` **Explanation:** - Customer 101 has purchases on 3 different dates. - Customer 102 has purchases on 2 different dates. - Other customers have only one purchase date.

📢 Instructions:

  • Ask anything relatd to above question only.
  • For new Question goto :

Study Help, Fast Answers

VIPSolutions focuses on clear, step‑by‑step explanations so you can learn quickly. Whether you need an AI‑generated walkthrough or a short hint to get unstuck, each solution is organized for fast reading and easy review later.

Search similar questions, compare approaches, and bookmark the best answers for revision. Our goal is simple: quick, reliable study help that feels natural—not noisy.