title: R integrate over values
body: <p>I have been trying to integrate the following function over r in <code>[0,1]</code>, but to no avail:</p>
  
  <pre><code>brownian_bridge &lt;- function(r){X[r*(length(X)-1)+1]-r*X[length(X)]}
  </code></pre>
  
  <p>X is a vector of length 1000, and r is defined as</p>
  
  <pre><code>r=seq(from=0,to=1,length=1000)
  </code></pre>
  
  <p>Furthermore, </p>
  
  <pre><code>X=cumsum(rnorm(1000,mean=0,sd=sqrt(1/1000)))
  </code></pre>
  
  <p>Now my question is: How can I integrate browian_bridge over r in [0,1]? Is there a built-in R function to do this? Standard tools such as integrate2() don't seem to work, because r is a sequence and not a function that holds for all r in [0,1].</p>