2016年7月19日火曜日

how to calculate moving average

when data is a vector of numeric like below.

> tail(data,n=10)
 [1] 199 158 165 137 170 142 127 174 158 156​


moving average is able to calculate with filter function. This is the case for 7 days simple moving average and omitting N/A results.

> filter(data,rep(1,7))[!is.na(filter(inc_daily,rep(1,7)))]/7


0 件のコメント: