[R] Improve code efficient with do.call, rbind and split contruction

Charles C. Berry ccberry at ucsd.edu
Sun Sep 4 01:16:44 CEST 2016


On Sat, 3 Sep 2016, Bert Gunter wrote:

> Chuck et. al.:
>
> As I said previously, my intuition about the relative efficiency of
> tapply() and duplicated() in the context of this thread was wrong.

My `intuition' was wrong, too.

But tapply() uses split() which runs quite fast. So not a big surprise, 
but if you look thru tapply() you'll notice it is well crafted in other 
ways. In particular, the way the `f' arg of split is constructed makes a 
big difference in timing (using a for loop to build up a mixed radix 
number). In fact interaction(f,g) needs about 3 times the time of 
tapply(f,list(f,g)) for just building an index.

Thanks for following up.

Best,

Chuck



More information about the R-help mailing list