in reply to transform a hash table into R dataframe or matrix with tab separator

For output, you may want to use the table() method. See the documentation. I scanned through it to see if there was a way to specify how the columns are separated, but I did not see anything.

You might want to look into Text::ASCIITable which has more options. UPDATE: see also Data::Frame.

But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

  • Comment on Re: transform a hash table into R dataframe or matrix with tab separator
  • Download Code

Replies are listed 'Best First'.
Re^2: transform a hash table into R dataframe or matrix with tab separator
by choroba (Cardinal) on Mar 30, 2016 at 20:44 UTC
    CPAN Weekly recommended Text::Table::Tiny on February the 28th.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      thx but i can find a good example to make work this module with a hash :(

        You just have to transform the hash into a reference to array of arrays.
        #!/usr/bin/perl use warnings; use strict; use Text::Table::Tiny qw{ generate_table }; my %periods = ( Mercury => { orbital => 0.24, rotation => 58.64 }, Venus => { orbital => 0.62, rotation => -243.02 }, Earth => { orbital => 1.00, rotation => 1.00 }, Mars => { orbital => 1.88, rotation => 1.03 }, Jupiter => { orbital => 11.86, rotation => 0.41 }, Saturn => { orbital => 29.46, rotation => 0.43 }, Uranus => { orbital => 84.01, rotation => -0.72 }, Neptune => { orbital => 164.8, rotation => 0.67 }, ); print generate_table( rows => [ [qw[ Planet Orbital Rotation ]], map [ $_, @{ $periods{$_} }{qw{ orbital rotation }} +], keys %periods ]);

        Data taken from Wikipedia.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,