I have a list with 8 columns, in which the first 6 are the same.
6 99999715 99999771 NM_001013399 0 - 23 0.0714286
6 99999715 99999771 NM_001013399 0 - 24 0.0178571
6 99999715 99999771 NM_001013399 0 - 25 0.1250000
I need to calculate the average for column 7 and column8, as well as $7*$8, and get the format like:
6 99999715 99999771 NM_001013399 0 - ave($7) ave($8) ave($7*$8)
How should I do this? thx
Haven't tried it, but it should be just:
{sum7+=$7; sum8+=$8; mul+=$7*$8} END {print sum7/NR,sum8/NR,mul/NR}
In response to popular demand, I'll add the printf.
{sum7+=$7; sum8+=$8; mul+=$7*$8}
END {printf "%s %4i %10.7f %10.7f\n", substr($0,0,49),sum7/NR,sum8/NR,mul/NR}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With