On Mon, May 9, 2011 at 6:55 PM, Andy Fingerhut wrote:
> (ns movavg
> (:gen-class))
>
> (set! *warn-on-reflection* true)
>
>
> (defn sliding-window-moving-average [window lst]
> (let [w (int window)
> w-1 (int (dec w))]
> (loop [rolling-sum (apply + (take w lst))
> last-w (obj
On May 9, 2011, at 6:45 AM, Andreas Kostler wrote:
> Hi all,
> I'm trying to calculate the moving average of a certain window size.
> One straight forward approach is:
> (defn lazy-avg [coll]
> (let [[sum cnt] (reduce
> (fn [[v c] val] [(+ val v) (inc c)])
> [
Hi all,
I'm trying to calculate the moving average of a certain window size.
One straight forward approach is:
(defn lazy-avg [coll]
(let [[sum cnt] (reduce
(fn [[v c] val] [(+ val v) (inc c)])
[0 0]
coll)]
(if (zero? cnt) 0 (/ sum cnt)