2
PRODUCT_DESCRIPTION INCENTIVE_DATE  Sale_Count
Cons DDA Revers 4/24/2018   145
HEP HEIL Sd New 4/25/2018   2
WPB Per Sel Tra 5/2/2018    11
Bus Checking 27 5/18/2018   233
VWP MM Growth 9 5/1/2018    562
Cons Sav Revers 5/18/2018   4
HELOC APP   5/2/2018    289
Referred Inv Re 4/27/2018   235
Non-Profit 180  5/2/2018    34

I am building a tool to detect if any sales products for the day did not properly post. So I am pulling daily sales data and seeing what products show up as 0. However, some products are cyclical and only post tues-thurs for example. I am putting 30 days of sales. I want to red flag products that are missing today, have a monthly average of over 10 sales per day and do not have a pattern of being 0 in regular intervals. My code looks like this so far:

csv <- read.csv('result_branch.csv')
csv$INCENTIVE_DATE <- as.character(csv$INCENTIVE_DATE)
csv$COST_CENTER <- as.character(csv$COST_CENTER)

csv <- spread(csv, INCENTIVE_DATE, Sale_Count)
csv[is.na(csv)] <- 0

branch <- csv$COST_CENTER
csv <- csv[, -1]


daily <- mutate(csv, prod_mean = rowMeans(csv))
daily$prod_mean <- round(daily$prod_mean, 2)



daily$Today_Missing <- daily[, 23] == 0
daily$Red_Flag <- (daily[, 25] == TRUE & daily[, 24] > 10) == TRUE
rownames(daily) <- branch



final <- final <- daily[order(-daily$Red_Flag, -daily$prod_mean), ]

Is there a way to filter out products that follow a regular pattern of being 0 sales certain days?

jamesB
  • 21
  • 2
  • 1
    Yes, there is a way. But you need to say exactly what pattern you are looking for. For example, do you want to find products that are always 0 on one or more given days of the week? –  May 23 '18 at 15:21
  • 1
    Please also provide a [mcve] - we don't know what is in your CSV file. –  May 23 '18 at 15:22
  • Hello Yes, that is exactly what I am looking for, and im new to stackoverflow so im not sure how to show you what is in my file – jamesB May 23 '18 at 15:52
  • @jamesB pls copy 10 lines from `csv` file and add as part of question. – MKR May 23 '18 at 16:10
  • See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example –  May 24 '18 at 11:02

0 Answers0