How do I find the rolling mean since the beginning of data using R?

前端 未结 2 567
孤独总比滥情好
孤独总比滥情好 2021-01-24 11:13

I am trying to find the rolling mean since the beginning of the data:

samp <- structure(list(samp = c(0.25, 0.4868, 0.6043, 0.5184, -0.3572, 
0.4685, 0.8264,          


        
相关标签:
2条回答
  • 2021-01-24 11:24

    You could use cummean from dplyr.

    cummean(samp$samp)
    
    0 讨论(0)
  • 2021-01-24 11:35

    How about cumsum(samp$samp)/1:nrow(samp)

    0 讨论(0)
提交回复
热议问题