Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backward average

Status
Not open for further replies.

steco

Technical User
Joined
Dec 7, 2006
Messages
5
Location
SE
Hi,
I have a large dataset which I would like to do a backward average on to see how the average develops. A simple example is shown below. The first column is my raw data, the second column would be my average, computed with awk:

1 3
2 3.5
3 4
4 4.5
5 5

In excel this is equivalent to AVERAGE(Ai:A$imax}. My awk knowledge is pretty limited and I've been struggling with this for a while now. Any help would be appreciated
 
A starting point:
Code:
awk '
{t[++i]=$1+0}
END{for(j=1;j<=i;++j){
s=0;for(k=j;k<=i;++k)s+=t[k];print t[j],s/(i-j+1)
}}' /path/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for that. It works a treat!
 
Status
Not open for further replies.

Similar threads

Replies
11
Views
337
  • Locked
  • Question Question
Replies
3
Views
121
Replies
3
Views
302

Part and Inventory Search

Sponsor

Back
Top