[R] Perl vs. R

John Day jday at csihq.com
Tue Jun 11 17:13:40 CEST 2002


Dear All,

I am being told that R can process text files and strings as well as Perl 
(and is certainly more elegant).

Being an R neophyte I need a little boost to get started. I have a little 
benchmark program in Perl that reads a delimited file, creates an inverted 
table and spits the file out again in key sorted order.

It's just a few lines of Perl (see below). Can someone write the equivalent 
in R? The benchmark and associated files are available from: 
http://www.lib.uchicago.edu/keith/crisis/benchmarks/invert/

You'll note on this page that Perl runs the benchmark in 3.5 secs. That was 
in 1997. My 5.6.1 version of Perl runs it in 0.18 secs now, on my 600Mhz 
Linux platform. Wondering how fast R will be in comparison.

Thanks,
John Day

FYI, here's the Perl source:

#!/local/bin/perl
# invert benchmark in Perl
# see <url:http://www.lib.uchicago.edu/keith/crisis/benchmarks/invert/
# Keith Waclena <k-waclena at uchicago.edu>

while (<STDIN>) {
     chop;
     ($a, $b) = split(/\t/);
     $B{$b} .= "\t$a";       # gotta lose leading tab later...
}

foreach $b (sort keys %B) {
     # lose the leading tab with substr...
     print "$b\t" . join("\t", sort(split(/\t/, substr($B{$b}, 1)))) . "\n";
}

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list