Re: [R] How to speed up R code?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue 18 Oct 2005 - 22:39:23 EST

Martin Lam wrote:
> Hi,
>
> I have written a piece of code, which is a variant of
> the random forest (rf) package algorithm, entirely in
> R. I know that some of the code in the rf package is
> written in c or c++. The problem is that the execution
> of my code in R takes a lot of time. To give you an
> example, the building and testing of data set with
> 20,000 instances using the random forest function from
> the rf package takes a few minutes while 'my' random
> forest's execution time is around 5 hours. So, I
> wonder if there are some ways to speed up the
> execution time.
>
> I've read in a similar post that using matrix instead
> of data.frame would actually speed up the R code. The
> format of my read-in data set is a "list", would the
> data set in matrix format (using as.matrix) be better?

One piece of advice I forgot to give to Xiaohua: try it! You can probably write slow code using *either* matrices or lists. You need to identify what is slow, and fix it.

Duncan Murdoch



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Oct 18 22:44:59 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:01:28 EST