Weighted moving average by SiggiSmara · Pull Request #54 · sgibb/MALDIquant (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this great PR. I really appreciate it (and I am very happy that you already included unit tests).
In fact .movingAverage
and .movingWeightedAverage
just differ in the calculation of their weights:1/length(windowSize)
vs myweigths<-1/2**abs(-halfWindowSize:halfWindowSize); myweights/sum(myweights)
.
What do you think about changing .movingAverage
into?:
.movingAverage <- function(y, halfWindowSize=2L, weighted=FALSE) { .stopIfNotIsValidHalfWindowSize(halfWindowSize, n=length(y)) windowSize <- 2L * halfWindowSize + 1L if (weighted) { weights <- 1 / 2^abs(-halfWindowSize:halfWindowSize) } else { weights <- rep.int(1L, windowSize) } .filter(y, hws=halfWindowSize, coef=matrix(weights/sum(weights), nrow=windowSize, ncol=windowSize, byrow=TRUE)) }
Additional I just have some comments about the coding style (everyone has his own, sorry).