Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Bucketing,Slicing and Reporting data across multiple dimensions

by blue_cowdawg (Monsignor)
on Aug 17, 2011 at 15:43 UTC ( [id://920718]=note: print w/replies, xml ) Need Help??


in reply to Bucketing,Slicing and Reporting data across multiple dimensions

This may be an oversimplification, but here is one idea:

#!/usr/bin/perl -w use strict; open FIN,"<dataset.dat" or die "dataset.dat:$!"; my $buckets={}; while(my $line=<FIN>){ chomp $line; my @f=split(",",$line); unless (exists($buckets->{$f[1]}){ $buckets->{$f[1]} = { count => 0, where =>[ ] }; } if ( $f[4] > 0 ) { $buckets->{$f[1]}->{count}++; push @{$buckets->{$f[1]}},$f[0]; } } close FIN; foreach my $key (sort keys %$buckets){ next unless $buckets->{$key}->{count} > 0 ; printf "%s\t%d\t%s\n", $key,$buckets->{$key}->{count}, join(",",sort @{$buckets->{$key}->{where}}); } # ####################################################### done

Caveat: not tested.. do not use for the control of a nuclear missile launch system.


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
  • Comment on Re: Bucketing,Slicing and Reporting data across multiple dimensions
  • Download Code

Replies are listed 'Best First'.
Re^2: Bucketing,Slicing and Reporting data across multiple dimensions
by Voronich (Hermit) on Aug 17, 2011 at 18:37 UTC
    Thanks very much! This looks remarkably close to what I'm looking for. Debugging now. (It's complaining about that "push" not referencing an array ref.)
    Me

      Doh!!! It should read:

      push @{$buckets->{$f[1]}->{where}},$f[0];


      Peter L. Berghold -- Unix Professional
      Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
        Ah. Domo o/
        Me
        The only other modification I made was:
        printf "%s\t%d\n", $key,$buckets->{$key}->{count};
        since I don't actually need the articulated list of IDs unless they're called for. The resulting list is really quite interesting. Almost all impact occurs across EVERY ID. But several only have impact on 3 or 4. Quite telling. Thanks again o/
        Me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-20 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found