Dear Markus,
You could use the following function (which loops only over the span of the
median, not over the data):
running.median <- function(x, lag){
n <- length(x)
X <- matrix(0, n, lag)
for (i in 1:lag) X[1:(n-i), i] <- x[-(1:i)]
apply(X, 1, median)[1:(n-lag)]
}
(You might also want to take a look at the smooth() function.)
I hope that this helps,
John
At 01:49 PM 1/20/2003 -0500, you wrote:
Hello,
does anyone know how to compute a moving median in Splus without using
explicit looping ?
Thanks so much,
Markus
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox@mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
|