[R] How to?
Jan.Schelling@hydro.com
Jan.Schelling at hydro.com
Fri Aug 25 10:43:25 CEST 2000
Yves,
to calculate e.g. the "running standard deviation" of a vector I use:
sdev.n <-
function(x, k) {
n <- length(x)
y <- rep(0, n)
for (i in (1+k):(n-k))
y[i] <- var(x[(i-k):(i+k)])
sqrt(y)
}
which does indeed get slow on larger vectors and I would be happy if anyone came
up with a smarter solution. I don't think I can use filter() from the ts package
for this purpose, can I?
regards
Jan Schelling
-----
cyg at sympatico.ca on 2000-08-24 14:57 GMT wrote:
>Ok, I used a dumb example and I kind of forgot that m was already a matrix.
>Prof Ripley suggested I use matrix operator in this case which is a lot
>faster.
>In fact what I'd like to know is what is the most efficient R way to do
>thing like a moving average on a vector. Something generic enough that one
>could use practically any function on a constant width window of the vector?
>Thanks
>Yves Gauvreau
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list