Vered, You should also know that performing a "query" on a piddle is quite straight-forward with the "where" and "which" methods.
$positive_data = $data->where($data > 0); The $positive_data piddle is a "slice" of the original data. This means you can manipulate the data in $positive_data and the modifications will "flow back" to the original piddle. David On Fri, Sep 19, 2014 at 3:30 PM, Craig DeForest <[email protected]> wrote: > > On Sep 18, 2014, at 3:31 PM, Vered Caspi <[email protected]> wrote: > > Hello, > I am new to PDL, and I wonder whether it is possible to do SQL-like > operations in PDL. > For example, is it possible to join (merge) tables? To use inner join, > left outer join etc? > Is it possible to concatenate tables, like R's rbind and cbind? > Thank you in advance, > Vered > > > > If by 'table' you mean '2-D structured array', then yes! Although it's > not really optimized for that kind of work. Sqlite and the DBH/DBI modules > (from CPAN) give direct SQL access. Joining and selection, in particular, > are operations for which SQL databases are optimized. PDL's target space > is large vector numeric calculations, though of course you can use it for > simple table manipulation -- provided your tables have all-numeric contents. > > # merge two tables (boneheaded way) > $c = $a->glue(1,$b); > # merge two tables (no dups) > $c = $a->glue(1,$b)->uniqvec; > > # inner join -- a bit more awkward. Construct (2-D) outer product mask > showing in which rows of > # A and B the key columns are equal, then find the coordinates where it > is true. Finally, index > # A and B to get the joined rows from A and joined rows from B in two > separate variables > $acol = $a->(($colno_in_a)); > $bcol = $b->(($colno_in_b)); > $equality_outer = $acol == $bcol->(*1); > $dexes = $equality_outer->whichND; > $a_from_join = $a->(:,($dexes->((0))); > $b_from_join = $b->(:,($dexes->((1))); > > # merge two tables with the same number of rows, concatenating columns > $c = $a->glue(0,$b); > > # merge two tables with the same number of columns, concatenating rows > $c = $a->glue(1,$b); > > > > > _______________________________________________ > Perldl mailing list > [email protected] > http://mailman.jach.hawaii.edu/mailman/listinfo/perldl > > -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan
_______________________________________________ Perldl mailing list [email protected] http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
