in reply to Sliding window intervals and average values for specific coordinates

Something like this?

#! perl -slw use strict; use List::Util qw[ sum ]; sub ave{ (sum( @_ )||0) / (@_||1) } my @intervals = map[ split ], do{ local @ARGV = 'intervals.dat'; <> }; chomp @intervals; my @markers = do{ local @ARGV = 'markers.dat'; <> }; chomp @markers; my %groups; my $first = 0; for my $int ( @intervals ) { my( $start, $stop, $val ) = @{ $int }; ++$first while $first < $#markers and $markers[ $first ] < $start; my $next = $first; push @{ $groups{ $markers[ $next ] } }, $val while $next++ < $#markers and $markers[ $next ] < $stop; } for my $marker ( @markers ) { print "$marker ", ave( @{ $groups{ $marker } } ); } __END__ C:\test>947611 10150 0 10250 0 10350 0.772 10450 0.594666666666667 10550 0.60125 10650 0.60125 10750 0.5585 10850 0.585333333333333 ... 18150 0.37475 18250 0.571 18350 0.523166666666667 18450 0.499 18550 0.4958 18650 0.4958 18750 0.372 18850 0.333714285714286

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

  • Comment on Re: Sliding window intervals and average values for specific coordinates
  • Download Code