Calculating moving average

前端 未结 16 1763
夕颜
夕颜 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:38

    vector_avg <- function(x){
      sum_x = 0
      for(i in 1:length(x)){
        if(!is.na(x[i]))
          sum_x = sum_x + x[i]
      }
      return(sum_x/length(x))
    }
    

提交回复
热议问题