title: I keep getting inf values when i run a function over an array
body: <p>I am writing a function in R that will compute a sum of squares between a binomial distribution and normal distribution and display the data as a function of <code>p</code></p>
  
  <p>Here is what I have:</p>
  
  <p>First I generate a random binomial distribution with probability p (n=100)</p>
  
  <p><code>random_binom&lt;-rbinom(100,100,p)</code></p>
  
  <p>Next, I find the probability that some random element has equal or less than the value np (the mean) and the standard deviation of <code>sqrt(np(1-p))</code> according to the normal distribution</p>
  
  <p><code>d_norm&lt;-dnorm(random_binom,p*100,sqrt(100*p*(1-p)))</code></p>
  
  <p>And then the probability that a random value in the distribution will have equal or less than the value of the mean according to the binomial distribution </p>
  
  <p><code>d_binom&lt;-dbinom(random_binom,100,p)</code></p>
  
  <p>finally I subtract the two, take the square and return it. </p>
  
  <p><code>result&lt;-sum((d_norm-d_binom)^2)</code>
  <code>return(result)</code></p>
  
  <p>Now within the console, I created a function for all this:</p>
  
  <p>myfunction:</p>
  
  <pre><code>function(p){
  random_binom&lt;-rbinom(100,100,p)
  d_norm&lt;-dnorm(random_binom,p*100,sqrt(100*p*(1-p)))
  d_binom&lt;-dbinom(random_binom,100,p)
  result&lt;-sum((d_norm-d_binom)^2)
  return(result)
  }
  </code></pre>
  
  <p>I want to pass in a vector for p where <code>p&lt;-(c(0:99)/100)</code>, but whenever I do that, the function returns </p>
  
  <p><code>inf</code></p>
  
  <p>rather than a vector of values. How can I get R to return a vector of values so that I can plot them? I have tried using lapply but that returns the data in a strange format: </p>
  
  <pre><code>[[95]]
  [1] 0.01064091
  
  [[96]]
  [1] 0.01418807
  
  [[97]]
  [1] 0.02647295
  
  [[98]]
  [1] 0.05065813
  
  [[99]]
  [1] 0.1179141
  
  [[100]]
  [1] 0.7342808
  </code></pre>
  
  <p>meaning each element is contained another element, making it very difficult to graph. </p>