Sliding window in R

前端 未结 2 454
轮回少年
轮回少年 2020-12-18 10:36

I have a dataframe DF, with two columns A and B shown below:

A                    B                  
1                    0             
3                           


        
2条回答
  •  天命终不由人
    2020-12-18 10:45

    The R library TTR has a number of functions for calculating averages over sliding windows

    SMA = simple moving average

    data$sma <- SMA(data$B, 3)
    

    More documentation is here http://cran.r-project.org/web/packages/TTR/TTR.pdf

提交回复
热议问题