Is there have something like R-lang columnbind or rowbind in raku. R-lang cbind
e.g.
my @matrix = ^100 .rotor(10);
my @cbind = cbind( @matrix [*;1..2].rotor(2) , @matrix [*;3..4].rotor(2) )
my @rbind = rbind ( @matrix [1..2;*].rotor(10) , @matrix [3..4;*].rotor(10) )
However, here is a table that specifies how it is defined for operator classes in Raku, which corresponds to the table in the above definition in the types and operators defined by the language: Operator class Identity value Equality Bool::True Arithmetic + 0 Arithmetic * 1
In Example 1, I’ll show how to join our two matrices using the data.frame function in R. As shown in Table 3, we have created a data table containing the columns of our matrices mat1 and mat2. Note that this data object has the data.frame class. Next; I’ll show how to convert this data frame back to the matrix class.
However, for operators built in to Raku, all operators with the same precedence level also have the same associativity. Setting the associativity of non-infix operators is not yet implemented. In the operator descriptions below, a default associativity of leftis assumed. Operator classification
Individual elements can be pulled out of a list using a subscript. The first element of a list is at index number zero: Variables in Raku whose names bear the @ sigil are expected to contain some sort of list-like object. Of course, other variables may also contain these objects, but @ -sigiled variables always do, and are expected to act the part.
rbind
is straightforward:
my @one = <a b c d>.rotor(2);
my @two = <e f g h>.rotor(2);
say @one.append: @two;
Update: edited thanks to comment.
If order does not matter so much, you can just use ∪ and it will turn into a set.
cbind
is a bit trickier, but doable:
say (@one Z @two).map( { @_.map: |* } )
Z
is the zip operator, which will interleave the elements of the first and the second list. But then well have too many nested lists, so we need to flatten the inner list here: { @_.map: |* }
. That will output
((a b e f) (c d g h))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With