title: function that computes the average of 20 rolls several thousand times and estimates the expectation and the variance of Y
body: <p>I need to write a function according to the info in the title. I'm trying to perform that with the following code:</p>
  
  <pre><code>my.function &lt;- function(x=1:6,Nsample=20,prob1=NULL) {
  
     rolling.die &lt;- sample(x, size=Nsample, replace=TRUE, prob=prob1)
  
     for (die in 1:10000) {
        die.sum &lt;- sum(rolling.die)
        average &lt;- die.sum/Nsample
     }
     return(var(average))
  }
  
  my.function()
  </code></pre>
  
  <p>But I always get N/A as a result. Could you, please, help me to understand what I am doing wrong?</p>