At Thu, 27 Dec 2012 15:38:08 -0500,
Sam Steingold wrote:
> so,
> 1. is there a way for a function to modify a global variable?

Use <<- instead of <-.

> 2. how would you vectorize this loop?

This is hard.  Your function has a feedback loop: an iteration depends
on the previous iteration's result.  A for loop is about as good as
you can do in this case.  sapply might help a bit, but it is really
just a for loop in disguise.

Since sample.int is used to generate indexes, you might try to
generate a bunch of indexes, take as many as don't overlap (i.e.,
collect all orthogonal updates) and do all of those updates at once.
If you really need the entropy after every iteration, however, then
this won't work for you either.

Neal

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to