Skip to content
Prev 314319 / 398503 Next

vectorization & modifying globals in functions

On Dec 27, 2012, at 12:38 PM, Sam Steingold wrote:

            
You could get some modest improvement by "vectorizing" the two  
lookups, additions, and assignments into one:

      d[a] <- d[a]-c(1,-1)

In a test with 100000 iterations, it yields about a  1.693/1.394 -1  =  
21 percent improvement.
The `unit` seems likely to throw an error since there is no argument  
for it to match.
You could have returned 'd' and the entropy result as a list. But what  
would be the point of saving 1e6 copies????
So if you replaced it in the global environment, you would only be  
seeing the result of the last iteration of the loop. What's the use of  
that????