Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to operator join two matrix in raku-lang?

Tags:

r

raku

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) )
like image 997
黃家億 Avatar asked Jan 11 '20 05:01

黃家億


People also ask

How is an operator class defined in raku?

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

How do I join two matrices in R?

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.

Do non-infix operators have the same associativity in raku?

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

How to pull out individual elements from a list using Raku?

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.


1 Answers

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))
like image 132
jjmerelo Avatar answered Oct 05 '22 11:10

jjmerelo