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!!
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With