Hi, I would like to average the data for certain rows in a tab-delimited file, for example the file looks like this:

Name10128 1A 33.2 A Test 0.71565 -0.011379692 Name4382 1A 34.3 A Test 0.9043 -0.035366577 Name1635 1A 34.9 A Test 0.836 -0.053808688 Name10267 1A 34.9 A Test 0.04575625 0.050878715 Name10039 1A 34.9 A Test 0.7606 -0.011123925 Name22270 1A 44.7 A Test 0.047 0.122532651 Name22285 1A 44.7 A Test 0 0.298871748 Name22701 1A 44.7 A Test 0.045 0.05038769 Name10054 1A 46.4 A Test 0 0.641618497

I want to scan down column3 and where there are identical entries, for example 34.9 and 44.7 I want to average the values in columns 6 and 7. So for the three rows that have 34.9 in column3, I would need to average the column6 values 0.836, 0.04575625 and 0.7606 and then replace those values in column6 with the average value, and do the same in column 7 for the values found there. What would be the most sensible way to proceed with this?


In reply to average a column in tab-delimited file by garyboyd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.