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
)
print(retail)
## BillID CustomerName Gender Membership Category Quantity CostPrice
## 1 501 Aman Male Gold Grocery 10 50
## 2 502 Riya Female Silver Electronics 1 20000
## 3 503 Karan Male Gold Clothing 3 800
## 4 504 Neha Female None Grocery 8 60
## 5 505 Rohit Male Silver Electronics 2 18000
## 6 506 Simran Female Gold Clothing 5 700
## SellingPrice Discount DeliveryType
## 1 70 100 Home
## 2 25000 2000 Store
## 3 1000 150 Home
## 4 80 50 Store
## 5 22000 500 Home
## 6 900 300 Home
#step2
retail$grossrevenue<- retail$Quantity * retail$SellingPrice
retail$Totalcost <- retail$Quantity * retail$CostPrice
retail$Netrevenue <- retail$grossrevenue * retail$Discount
retail$profit <- retail$Netrevenue - retail$Totalcost
print(retail$profit)
## [1] 69500 49980000 447600 31520 21964000 1346500
#step 3
gm <- subset(retail, Membership=="Gold" & profit>5000 & DeliveryType=="Home")
print(gm)
## BillID CustomerName Gender Membership Category Quantity CostPrice
## 1 501 Aman Male Gold Grocery 10 50
## 3 503 Karan Male Gold Clothing 3 800
## 6 506 Simran Female Gold Clothing 5 700
## SellingPrice Discount DeliveryType grossrevenue Totalcost Netrevenue profit
## 1 70 100 Home 700 500 70000 69500
## 3 1000 150 Home 3000 2400 450000 447600
## 6 900 300 Home 4500 3500 1350000 1346500
loss <- subset(retail, profit < 0)
print(loss)
## [1] BillID CustomerName Gender Membership Category
## [6] Quantity CostPrice SellingPrice Discount DeliveryType
## [11] grossrevenue Totalcost Netrevenue profit
## <0 rows> (or 0-length row.names)
elecit <- subset(retail, Category=="Electronics" & Quantity>=2 & Discount>1000 & profit>0)
print(elecit)
## [1] BillID CustomerName Gender Membership Category
## [6] Quantity CostPrice SellingPrice Discount DeliveryType
## [11] grossrevenue Totalcost Netrevenue profit
## <0 rows> (or 0-length row.names)
pre <- subset(retail, Netrevenue>20000 | Membership=="Gold")
print(pre)
## BillID CustomerName Gender Membership Category Quantity CostPrice
## 1 501 Aman Male Gold Grocery 10 50
## 2 502 Riya Female Silver Electronics 1 20000
## 3 503 Karan Male Gold Clothing 3 800
## 4 504 Neha Female None Grocery 8 60
## 5 505 Rohit Male Silver Electronics 2 18000
## 6 506 Simran Female Gold Clothing 5 700
## SellingPrice Discount DeliveryType grossrevenue Totalcost Netrevenue profit
## 1 70 100 Home 700 500 70000 69500
## 2 25000 2000 Store 25000 20000 50000000 49980000
## 3 1000 150 Home 3000 2400 450000 447600
## 4 80 50 Store 640 480 32000 31520
## 5 22000 500 Home 44000 36000 22000000 21964000
## 6 900 300 Home 4500 3500 1350000 1346500
#step4