Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perl @array data into R

Tags:

r

perl

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'.

a) by using R:

datos<-scan("datos.txt")
pdf("xh.pdf")
hist(datos)
dev.off()

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

Thanks!!

like image 962
JRamon Blas Avatar asked Dec 29 '25 01:12

JRamon Blas


2 Answers

Perl is not a statistics-focused language like R, so charting functions are not likely to be found in the core. But with Perl being a general purpose language, it can do anything R can, and you'll often find what you want by searching CPAN. A quick glance yields some promising candidates:

  • Statistics::Histogram
  • PDL::Graphics::Prima
  • Math::GSL::Histogram
like image 132
Richard Simões Avatar answered Dec 31 '25 13:12

Richard Simões


You can also try the perl module

Statistics::R.

This seems to be supported for windows and linux. I haven't really used it though. Thus, I don't know if it is easy to install (or if the installer pulls in a whole lot of dependencies, or how much manual configuration is required).

It seems to be pipe-based, and the OS-check for win32-based systems is really simple, so I'd think it works better on linux than on windows.

But the module seems to be actively developed (as of 2012). And for your use case, sending a few simple commands from perl to R, it should be worth a look.

like image 33
knb Avatar answered Dec 31 '25 13:12

knb