1

So, I want to calc the mean of values in a time series as it goes along. It's super easy in excel, let me show you what I mean:

enter image description here

The window size increases by 1 for each row down. I tried to do this with the data.table function like so:

DT[,RollingAvg:=lapply(.SD,frollmean,n=.I,fill=NA),.SDcols=c("Value")]

Thinking I was being clever by having n = .I which represents the row number... Doesn't work, returns a list in fact.

So how would I replicate the easy excel formula? (Yes, I prefer data.table over dplyr type solutions)

Thanks

wizard_draziw
  • 505
  • 1
  • 5
  • 17
  • Don't you want a cumulative mean? `dplyr::cummean(5:1)` or many other options here https://stackoverflow.com/questions/11074665/calculate-cumulative-average-mean – Ronak Shah Apr 04 '20 at 01:37

0 Answers0