So I have a data frame
x=df (Products =c(1,2), Run Cal Week = (CW23,CW24) , Demand =c(20,20,20,20,20,20), Cal.Week =(CW23,CW24,CW25) Product Cal Week Demand Run Cal Week 1 CW23 20 CW23 1 CW24 20 CW23 1 ,CW25 20 2 2 2
Ok so i have 11 run.cal.weeks and for each run i have a forecast of 20 calender weeks with demand for each product.
I need to calculate the Average of each Run Cal Week for each product.
This Average is the max of the average up to 10 weeks and average of the next 20.
So I had the strategy that i do a split and then add a counter and go with a groupby mean function. But it does not work how i did it:
data_count=c(1:26) data_group <- data_test %>%group_by(Product, Run.Cal.Week)%>% cbind (data_test,data_count) df1 <- df %>% group_by(Product, Run.Cal.Week) %>% summarize(mean26 = mean(Orders), mean13= mean(valueOrders[week<=13]))
I am new to R and I do think i am making a mistake here. Thanks a lot for the help
UPDATE: found the function
mutate(counter = row_number(ProjectID)) and it worked