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?