Prev: Another chess related text file processing problem
Next: Temporary environment variable assignment
From: Ben Bacarisse on 18 Apr 2010 13:03 "Dr. David Kirkby" <david.kirkby(a)onetel.net> writes: > On Apr 14, 6:17 pm, Seebs <usenet-nos...(a)seebs.net> wrote: >> On 2010-04-14, pk <p...(a)pk.invalid> wrote: >> >> > IIUC, shouldn't it be more like >> >> > awk -v points=3 -f thisfile.awk: >> >> > { a[NR % points] = $1; >> > if(NR>=points) { >> > total = 0; >> > for (i = 0; i < points; ++i) { total = total + a[i]; } >> > print (total / points); >> > } >> > } >> >> Maybe! A lot of people don't have a clear definition of what they mean >> by a "moving average", I just figured I'd illustrate the simplest case... <snip> > > Thank you for that. It works perfectly. In my case, the number of data > points is much greater than the likely number of points I want to > average over, so extra test added is not strictly necessary. Probably too late, but there is something unsettling about adding up the total every time. I'd write it like this: { total += $1 - a[NR % points]; a[NR % points] = $1 } NR >= points { print total / points } -- Ben.
First
|
Prev
|
Pages: 1 2 Prev: Another chess related text file processing problem Next: Temporary environment variable assignment |