Skip to content
Prev 313147 / 398506 Next

Vectorizing integrate()

You can't vectorize the loop because integrate() is not vectorized, but you
really need to pass only one index variable if you redefine your function so
that you are not re-creating it for each step in the loop. That would let
you use sapply(). Here's a toy example that should generalize to your
problem:
n=w[i])$value)
[1] 1.0000000 0.5000000 0.3333333 0.2500000 0.2000000

Creating the function outside the loop should speed things up. 

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352