Sorry if this was answered. Today I have done many examples, but cannot find what I'm trying to do.
I have a dataset that I need to calculate a 3 point moving average. I created some dummy data below:
set.seed(1234) data.frame(Week = rep(seq(1:5), 3), Section = c(rep("a", 5), rep("b", 5), rep("c", 5)), Qty = runif(15, min = 100, max = 500), To = runif(15, min = 40, max = 80))
I want to calculate the MA for each group based on the "Section" column for the "Qty" and "To" columns. Ideally, the output would be a data table. The moving average will start at Week 3, so there will be an average wks of 1: 3
I am trying to master the data.table package, so the solution using this will be great, but otherwise anyone would be very grateful.
For reference only, my actual dataset will be approx. 70 sections with c.1M rows. I found that data.table will be extremely fast when crunching these volumes so far.
source share