Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: transforming XY data to X and Multiple Y column data?

by sundialsvc4 (Abbot)
on Sep 27, 2010 at 14:04 UTC ( [id://862215]=note: print w/replies, xml ) Need Help??


in reply to transforming XY data to X and Multiple Y column data?

For a task like this one, everything depends on your data-structure.   It appears that your data consists of “lists of zero-or-more values” indexed by two keys.   The first key is introduced at the beginning of each group, e.g. id1.   The second is introduced with each row.

The most appropriate Perl structure, it seems to me, is:   “a hashref of hashrefs of arrayrefs.”   (If you happen to know that the second dimension is always contiguous integers, it might be “a hashref of arrayrefs of arrayrefs.”)

Each time you encounter a line which introduces a new key (such as id3), you will create a new hashref entry for it, and remember what it is.   When you encounter a line of the other kind, the process is similar.   You know that an entry for the major-key (id3) exists.   So, now, check that this hashref contains the minor-key; create a new empty entry (containing an arrayref) if it doesn’t.   push the new value onto this array.

Output will make heavy use of sort keys hashref.

You may need to use a sort-function in the sort clauses to ensure that comparisons are numeric.

The program is not quite straightforward, but it is uncomplicated.

  • Comment on Re: transforming XY data to X and Multiple Y column data?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://862215]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-19 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found