title: R error: cannot coerce type 'closure' to vector of type 'double'
body: <p>I'm getting an error in my R program that says:</p>
  
  <blockquote>
    <p>Error in as.double(x) :    cannot coerce type 'closure' to vector of
    type 'double'</p>
  </blockquote>
  
  <p>Here's my code, I can't figure out where it's coming from:</p>
  
  <pre><code>norm.pop = rnorm(100000,10,sd = 1)
  exp.pop = rexp(100000, rate = 1/10)
  true.mean = 10
  
  norm.func = function(n, N, type)
  {
    if(type == "N")
      pop = norm.pop
    else if(type =="E")
      pop = exp.pop
    all.the.probs = sapply(1:N, function(i)
    {
      the.sample = sample(pop, size = n, replace = TRUE)
      x.bar = mean(the.sample)
      sd.norm = sd(sample)/sqrt(n)
      z.score = 1.96
      upper.fence = x.bar + z.score*sd.norm
      lower.fence = x.bar - z.score*sd.norm
      if((true.mean &gt;= lower.fence) &amp; (true.mean &lt;= upper.fence))
      {
        return(1)
      }
      else
      {
        return (0)
      }
    })
  
    result = mean(all.the.probs)
  
    return (result) 
  }
  
  norm.func(10, 10000, "N")
  </code></pre>