Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Imputation of data

by CountZero (Bishop)
on Jan 25, 2016 at 17:24 UTC ( #1153593=note: print w/replies, xml ) Need Help??


in reply to Imputation of data

Assuming that you only want to delete those rows with "wildcards" that cannot match any other row (with or without wildcards) you cannot just simply delete all rows that contain a "9".

To check this assumption I have added an extra row of data "2 2 9 2 2". That row cannot match any of the other rows and therefore should not be deleted.

use Modern::Perl qw/2015/; my %data; # First we transform and load the data into a hash while (<DATA>) { chomp; my $data = $_; s/([^9 ])/[$1X]/g; s/9/[0129]/g; s/X/9/g; $data{$_} = $data; } #Then we check if records with missing data are unique for my $testrecord ( keys %data ) { next unless $data{$testrecord} =~ m/9/; for my $record ( keys %data ) { next if $data{$record} eq $data{$testrecord}; #don't check you +rself if ( $data{$record} =~ m/$testrecord/ ) { delete $data{$testrecord}; last; } } } say $data{$_} for keys %data; __DATA__ 2 2 0 1 0 2 2 0 2 1 0 2 1 1 0 0 1 1 1 0 2 2 0 0 0 2 9 0 2 1 0 2 0 1 0 2 2 0 9 0 2 2 9 2 2
Output:
0 1 1 1 0 0 2 0 1 0 2 2 0 1 0 2 2 0 0 0 2 2 0 2 1 0 2 1 1 0 2 2 9 2 2

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
Re^2: Imputation of data
by garyboyd (Acolyte) on Jan 26, 2016 at 09:11 UTC

    Thanks for all the replies, unfortunately a simple grep won't work, as CountZero mentions - a row such as "2 2 9 2 2" would be considered unique, and should not be deleted.

Re^2: Imputation of data
by garyboyd (Acolyte) on Jan 26, 2016 at 11:35 UTC

    the code provided by CountZero works perfectly, thanks once again for everybodys help!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1153593]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-07-22 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (452 votes). Check out past polls.

    Notices?