Hi i have data with two columns like below.
I want to find average of column values like if the value in column 2 is between 0-250000 the average of column 1 is some xx and average of column2 is ww then if value is 250001-5000000 average of column 1 is yy and average of column 2 is zz.
And my interval to find the average is 250000
Can anyone help me on this.
Thanks.
198.25 250000
192 300000
128.5 100000
88 123456
96.25 340000
167.75 540000
401 430000
2008.5 199074
2883 199072
214.75 198959
621.5 198931
Show the output you'd want for this input please.
This is output to given input
877.5 181356
229.83 356666.66
167.75 540000
I cannot find any combination of numbers from that first column which, in sum or average, equal 877.5
The average of
128.5 100000
96.25 340000
401 430000
2883 199072
...comes close, but I can't understand why they'd be averaged together, since they're in different slots according to your criteria
Average is based on 2nd column if 2nd column values are in between 0-250000 average them then if values are in between 250001-500000 average them them if values are in between 500001-750000 average them the interval for each is 250000.
Your answer is almost near but i have huge data file to perform this so i may get error in final output.
Anyways thanks for replying.
---------- Post updated at 05:23 PM ---------- Previous update was at 05:05 PM ----------
sum coming to 877.5 is
(198.25 + 128.5 + 88 + 2008.5 + 2883 + 214.75 + 621.5)/7 = 877.5
Hi, try this:
awk '{i=int(($2-1)/r); A+=$1; B+=$2; C++} END{for(i in A)print A/C, B/C}' r=250000 infile
1 Like