Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Remove particular columns of a matrix

by Marshall (Canon)
on Sep 09, 2022 at 03:07 UTC ( [id://11146773]=note: print w/replies, xml ) Need Help??


in reply to Remove particular columns of a matrix

Some index utils in List:MoreUtils are useful;
use strict; use warnings; use List::MoreUtils qw(firstidx indexes); use Data::Dump qw(pp); my @matrix = ( [qw(t1 t1 t2 t2 t2)], [qw(a1 a2 a1 a1 a2)], [qw(intron intron UTR_CG UTR UTR)], ); die "No UTR_CG column!" unless ( (firstidx {$_ eq 'UTR_CG'}@{$matrix[- +1]}) > -1); my @utr_cols = indexes { $_ eq 'UTR' } @{$matrix[-1]}; die "Must have 2 or more UTR columns!" unless (@utr_cols >= 2); shift @utr_cols; #save first seen UTR column delete @{$matrix[$_]}[@utr_cols] for (0..@matrix-1); pp \@matrix; __END__ [ ["t1", "t1", "t2", "t2"], ["a1", "a2", "a1", "a1"], ["intron", "intron", "UTR_CG", "UTR"], ]

Log In?
Username:
Password:

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

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

    No recent polls found