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