in reply to Average columns based on header name
This might not be the best way for the final program, but it gives you basically the idea for one group of values. Then you need to create an array with the steps (10, 20, 30...100), for example:DB<24> $in = "0.4% 0.7% 1.1% 1.4% 1.8% 2.2% 2.5% 2.9% 3.3% 3.6% 4.0% + 4.3% 4.7% 5.1% 5.4% 5.8% 6.2% 6.5% 6.9% 7.2% 7.6% 8.0% 8.3% 8.7% 9.1 +% 9.4% 9.8% 10.1% 10.5% 10.9% 11.2<.3% 3.6% 4.0% 4.3% 4.7% 5.1% 5.4% +5.8% 6.2% 6.5% 6.9% 7.2% 7.6% 8.0% 8.3% 8.7% 9.1% 9.4% 9.8% 10.1% 10. +5% 10.9% 11.2%"; DB<25> $in =~ s/%//g; # remove the percentage signs DB<26> p $in 0.4 0.7 1.1 1.4 1.8 2.2 2.5 2.9 3.3 3.6 4.0 4.3 4.7 5.1 5.4 5.8 6.2 6 +.5 6.9 7.2 7.6 8.0 8.3 8.7 9.1 9.4 9.8 10.1 10.5 10.9 11.2 11.6 DB<26> @val = split /\s/, $in; DB<27> while ($i = shift @val and $i <= 10) {$sum += $i; $j++} DB<28> print $sum/$j; 5.07037037037037 DB<29> unshift @val, $i if $i > 10; # put back the last value into t +he array if needed
and include the above process in another external loop going through the steps. Then you finally need yet another more external loop for going through the whole data.DB<32> @steps = map $_ * 10, 1..10; DB<33> x \@steps 0 ARRAY(0x600639618) 0 10 1 20 2 30 3 40 4 50 5 60 6 70 7 80 8 90 9 100
I hope this helps you get going. If you understand the above, you can probably do the whole thing.
|
|---|