title: Is it possible to `for` loop the `sapply` in R?
body: <p>I was wondering why my object <code>CI</code> doesn't correctly return the full (11 paired answers) outputs from the <code>for()</code> loop in the following function? Instead, the <code>CI</code> returns 11 single numbers.</p>
  
  <pre><code>N = 30 ; df = 118 ; d = 1
  
  f &lt;- function (ncp, alpha, q, df) {
   abs(suppressWarnings(pt(q = d*sqrt(N), df = df, ncp, lower.tail = FALSE)) - 
     alpha)
        }
  
   a = mapply(c, as.list(20:30), as.list(-20:-30), SIMPLIFY = FALSE) # a list of paired values
  
   CI &lt;- numeric(length(a))
  
   for(i in 1:length(a)){
  
  CI[i] = sapply(c(0.025, 0.975),
           function(x) optimize(f, interval = a[[i]], alpha = x, q = d*sqrt(N), df = df, tol = 1e-10)[[1]])
  
      }  
  
  CI # just returns one paired of the 11 paired answers expected!
  </code></pre>