in reply to Re^2: average a column in tab-delimited file
in thread average a column in tab-delimited file
Please explain in words, how you would do it, using paper and pencil
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: average a column in tab-delimited file
by garyboyd (Acolyte) on Jan 31, 2012 at 15:36 UTC | |
well I've written something that almost does the job, except it goes wrong on the very last line of the file. I read the file into an array and calculate the averages which I then put into a hash and then iterate through the array and lookup values from the hashes. I'm sure there's a more elegant way to do it though....
| [reply] [d/l] |
by Cristoforo (Curate) on Feb 02, 2012 at 01:09 UTC | |
it goes wrong on the very last line of the file Between the 2 foreach blocks, add these 2 lines of code.
There were alot of warnings about some of your variables not being initialized. To get rid of the warnings, I initialized them with values from the first line in the file. Posting some of that code here.
There are 2 different criteria about what you use to create a group to average. In your code, a group to average is determined by the code, if ($location == $prev_loc) .... But you are also joining the $chr and $location keys for the 2 different hashes here. I believe this leaves the door open for difficult to trace behaviors. It works without error with the sample data provided, but it could break down with an actual file. Would you want a line like if ($join eq $prev_join)...?
| [reply] [d/l] [select] |
by Cristoforo (Curate) on Feb 04, 2012 at 20:50 UTC | |
I compared the join of (chr, location), to determine the end of a run instead of just location by itself.
Update: Redid substitution for closer spec. | [reply] [d/l] |
by Anonymous Monk on Feb 05, 2012 at 16:22 UTC | |
well I've written something that almost does the job, except it goes wrong on the very last line of the file. Did you at any point sit down with pencil and paper, and write out steps to solve this problem as human computer with pen and paper? | [reply] |