Calculating moving average

前端 未结 16 1772
夕颜
夕颜 2020-11-21 23:55

I\'m trying to use R to calculate the moving average over a series of values in a matrix. The normal R mailing list search hasn\'t been very helpful though. There doesn\'t s

16条回答
  •  终归单人心
    2020-11-22 00:36

    In data.table 1.12.0 new frollmean function has been added to compute fast and exact rolling mean carefully handling NA, NaN and +Inf, -Inf values.

    As there is no reproducible example in the question there is not much more to address here.

    You can find more info about ?frollmean in manual, also available online at ?frollmean.

    Examples from manual below:

    library(data.table)
    d = as.data.table(list(1:6/2, 3:8/4))
    
    # rollmean of single vector and single window
    frollmean(d[, V1], 3)
    
    # multiple columns at once
    frollmean(d, 3)
    
    # multiple windows at once
    frollmean(d[, .(V1)], c(3, 4))
    
    # multiple columns and multiple windows at once
    frollmean(d, c(3, 4))
    
    ## three above are embarrassingly parallel using openmp
    

提交回复
热议问题