[R] How to write efficient R code
Ko-Kang Kevin Wang
k.wang at auckland.ac.nz
Tue Feb 17 20:24:20 CET 2004
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
> Lennart.Borgman at astrazeneca.com
> Sent: Wednesday, February 18, 2004 3:36 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How to write efficient R code
>
> I have been lurking in this list a while and searching in the
> archives to
> find out how one learns to write fast R code. One solution
> seems to be to
> write part of the code not in R but in C. However after
> finding a benchmark
> article (http://www.sciviews.org/other/benchmark.htm) I have been
more
> interested in making the R code itself more efficient. I
> would like to find
> more info about this. I have tried to mail the contact person for
the
> benchmark, but I have so recieved no reply.
One way to make your codes more efficient is to use "vectorisation" --
vectorise your codes. I'm not sure where you can find more
information about it, but an example would be to use the apply()
function on a data frame instead using a loop. Avoid loops if you
can.
Kevin
--------------------------------------------
Ko-Kang Kevin Wang, MSc(Hon)
SLC Stats Workshops Co-ordinator
The University of Auckland
New Zealand
More information about the R-help
mailing list