title: How to convert a loop which is dependent on index, to apply() to improve speed in R?
body: <p>My loop looks like this:</p>
  <pre><code>my.loglik.cv &lt;- function(Y,h){
  L_h &lt;- 0
  for(i in 1:length(Y)){
  L_h&lt;-L_h+log(my.kernel.density.estimator(Y[i],Y[-i],h))}
  return(L_h)
  }
  </code></pre>
  <p>as you see, it is important to me to subset Y by [-i], but I need to use apply family to improve the performance. Any solution?</p>
  <p>Thanks</p>