Average columns based on header name


Login or Register to Reply

 
Thread Tools Search this Thread
# 8  
Old 03-18-2016
Not without way more evidence.

---------- Post updated at 09:23 ---------- Previous update was at 09:13 ----------

The averaging error in the last record corrected. Try
Code:
paste FILE1 FILE2 |  awk '
NR == 1         {print "Gene    Average_10%     Average_20%     Average_30%     Average_40%     Average_50%     Average_60%"\
                        "       Average_70%     Average_80%     Average_90%     Average_100%"
                 printf "%s", $2
                 OFS="\t"
                 ST = B
                 F = 2
                 next
                }
$1+0 < ST       {SUM+=$2; next}
$1+0 == ST      {SUM+=$2; if (!getline) F--}
                {printf "%s%.6f", OFS, SUM/(NR-F)
                 SUM = $2
                 ST = ST%100 + B
                 if (ST == B) printf RS
                 F = NR}
' B=10
Gene    Average_10%     Average_20%     Average_30%     Average_40%     Average_50%     Average_60%     Average_70%     Average_80%     Average_90%     Average_100%
Gene1   0.008554        0.002911        0.012579        0.011645        0.018438        0.005032        0.010675        0.002013        0.010675        0.029597
        0.013662        0.017879        0.006343        0.014586        0.011292        0.005367        0.019761        0.014638        0.010822        0.023525
        0.016471        0.013692        0.007951        0.012049        0.001095        0.015903        0.008215        0.007951        0.007120        0.017526
        0.020158        0.019438        0.007866        0.007111        0.018490        0.016716        0.021334        0.017208        0.006637        0.038876
        0.010437        0.027014        0.003845        0.010064        0.015891        0.010986        0.010594        0.019775        0.014302        0.023306
        0.006866        0.022512        0.006866        0.015008        0.010152        0.014648        0.016332        0.015106        0.016332        0.041934
        0.015733        0.025127        0.004425        0.014697        0.015171        0.017699        0.014697        0.016225        0.019438        0.032238
        0.009547        0.017993        0.005207        0.006277        0.023433        0.009981        0.010461        0.015622        0.013390        0.011298
        0.010116        0.009754        0.003613        0.002787        0.010451        0.018064        0.042501        0.024567        0.019509        0.022296
        0.011702        0.017866        0.005363        0.007523        0.004231        0.023403        0.014575        0.008289        0.015515        0.034321
        0.005176        0.018854        0.007476        0.018854        0.008872        0.023577        0.012199        0.024152        0.019963        0.038816
        0.025605        0.014681        0.008304        0.012012        0.012012        0.008304        0.022022        0.014533        0.007341        0.024024
        0.016357        0.014646        0.014410        0.014271        0.010515        0.027262        0.025162        0.031935        0.025537        0.025162

Does the "division by zero" error occur in here as well?
This User Gave Thanks to RudiC For This Post:
jacobs.smith (03-18-2016)
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Average of a columns from three files nans Shell Programming and Scripting 5 09-07-2017 02:43 PM
Find columns in a file based on header and print to new file LMHmedchem Shell Programming and Scripting 11 11-26-2016 08:16 AM
Average across multiple columns - awk theflamingmoe Shell Programming and Scripting 6 11-21-2016 12:09 AM
Keep only columns in first two rows based on partial header pattern. aachave1 UNIX for Beginners Questions & Answers 4 08-30-2016 05:19 PM
Match first two columns and average third from multiple files ncwxpanther Shell Programming and Scripting 18 03-05-2015 12:04 PM
Match first two columns and calculate percent of average in third column ncwxpanther Shell Programming and Scripting 1 02-13-2015 10:27 AM
Average across multiple columns group by ritakadm Shell Programming and Scripting 10 01-26-2015 08:37 PM
Make copy of text file with columns removed (based on header) LMHmedchem Shell Programming and Scripting 9 01-22-2015 05:19 AM
Writing a script to take the average of two columns every 3 rows evelibertine UNIX for Dummies Questions & Answers 1 11-18-2013 03:49 PM
How to calculate average of two columns and copy into another file? Lokaps Shell Programming and Scripting 3 11-05-2013 10:13 AM
Extract columns based on header aec Shell Programming and Scripting 4 04-23-2013 03:45 PM
Average, min and max in file with header, using awk kayakj Shell Programming and Scripting 11 02-21-2013 05:21 AM
Average of columns with values of other column with same name isildur1234 Shell Programming and Scripting 3 12-13-2012 06:39 AM
awk based script to find the average of all the columns in a data file ks_reddy Shell Programming and Scripting 4 09-06-2012 02:56 PM
Taking the average of two columns and printing it on a new column evelibertine UNIX for Dummies Questions & Answers 11 07-25-2012 04:23 PM