You can use rollmean
, but set align='right'
. Or you could use rollmeanr
, which has align='right'
as the default.
ma3 <- rollmeanr(x[,1],3,fill=NA)
...but you would still need to lag the result. Another solution is to use rollapply
with a list for the width
argument:
ma3 <- rollapplyr(x[,1],list(-(3:1)),mean,fill=NA)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…