[R] get data from Perl arrays

Till Bayer till.bayer at kaust.edu.sa
Mon Apr 2 08:32:10 CEST 2012


On 4/2/2012 8:20 AM, José Ramón Blas Pastor wrote:
> Hi,
>
> a very simple doubt, but I do not know how to manage this.
>
> I want to plot a histogram for all data in 'datos.txt'.

> b) How could I invoke R inside Perl to do the same??
> #!/usr/bin/perl
> open(DAT,"datos.txt");
> while (<DAT>) {
>   chomp;
>   push(@datos,$_);
> }
> #now I want a histogram of values in @datos

You can use Statistics::R for that, for example:

use Statistics::R;

my $R = Statistics::R->new();

$R->set( 'data', \@datos );
$R->run( q`d<-hist(data)` );
$R->run( qq`png("histogram.png")` );
$R->run( qq`plot(d, main="Histogram")` );
$R->run( q`dev.off()` );


Cheers,

Till



More information about the R-help mailing list