[18936] in s-news-athena
[S] moving median
daemon@ATHENA.MIT.EDU (fan@katan.cybercom.net)
Fri Aug 13 12:46:29 1999
From: fan@katan.cybercom.net
Date: Fri, 13 Aug 1999 12:41:18 -0400
Message-Id: <199908131641.MAA27751@katan.cybercom.net>
To: s-news@wubios.wustl.edu
This question is related to the previous moving average question:
Instead of mean, I want to compute the 30-term moving median.
The filter() and cumsum() methods will not work. There might be some
S usage which works on this directly, other than using loop. If you have an
idea, let me know.
The previous method of using apply to a gigantic matrix will work.
A matrix of 10000x30, however, is slow to work on.
#x is a sequence of 1000 data points
x<-rnorm(1000)
#y is the 30-term running median of x;
#i.e.: y[i] <- median(x[i:(i+29)]), i = 1, ..., 971
#Surely, a loop solves it:
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news