############################
# STEP 1: Create Data Frame
############################
retail <- data.frame(
BillID = c(501,502,503,504,505,506),
CustomerName = c("Aman","Riya","Karan","Neha","Rohit","Simran"),
Gender = c("Male","Female","Male","Female","Male","Female"),
Membership = c("Gold","Silver","Gold","None","Silver","Gold"),
Category = c("Grocery","Electronics","Clothing","Grocery","Electronics","Clothing"),
Quantity = c(10,1,3,8,2,5),
CostPrice = c(50,20000,800,60,18000,700),
SellingPrice = c(70,25000,1000,80,22000,900),
Discount = c(100,2000,150,50,500,300),
DeliveryType = c("Home","Store","Home","Store","Home","Home"),
stringsAsFactors = FALSE
)
############################
# STEP 2: Calculation Columns
############################
retail$GrossRevenue <- retail$Quantity * retail$SellingPrice
retail$TotalCost <- retail$Quantity * retail$CostPrice
retail$NetRevenue <- retail$GrossRevenue - retail$Discount
retail$Profit <- retail$NetRevenue - retail$TotalCost
############################
# STEP 3: Multi-Condition Analysis
############################
# 1. Gold + Profit > 5000 + Home
gold_highprofit_home <- subset(retail,
Membership=="Gold" &
Profit>5000 &
DeliveryType=="Home")
# 2. Loss making transactions
loss_transactions <- subset(retail, Profit < 0)
# 3. Electronics Qty>=2, Discount>1000, Profit>0
electronics_condition <- subset(retail,
Category=="Electronics" &
Quantity>=2 &
Discount>1000 &
Profit>0)
# 4. Premium customers
premium_customers <- subset(retail,
NetRevenue>20000 |
Membership=="Gold")