How can I pass sparse matix from Perl to R?

I have a very sparse Perl matrix (array of arrays) where the values ​​are undefequivalent to zeros. It has 10-1000 rows and up to 100 thousand columns. It looks like this:

$ARRAY1 = [
            [
              ( undef ) x 1069,
              1,
              ( undef ) x 47,
              1,
              ( undef ) x 11,
              2,
              ( undef ) x 50,
              1,
              ( undef ) x 23,
              1,
              ( undef ) x 6033,
              ...
            ],
            [
              ...
            ],
            ...
          ]

... as I said - very meager.

I want to use this matrix in an R script (see previous post ). One way is to print the table in a file from Perl - one line per line and print it 0anytime we run undef.

But maybe there is a better, more compact way to convey this sparse matrix?

+3
source share
2 answers

This is a moderately severe problem.

, , Perl:

  • R, slam, SparseM,....
  • , , , , , (x,y,value), value (x,y).
  • Perl-, tempfile.
  • R .

Fancier . .

+3

, perl R. , , , ( ) - . , :

80000 200
1069 0 1
1117 0 1
1129 0 2
...
0

Source: https://habr.com/ru/post/1773117/


All Articles