title: Calculating Mean value with R
body: <p>I am trying to calculate the mean of a random variable using R, with the help of the Monte-Carlo-Simulation method, so I wrote this function:</p>
  
  <pre><code>&gt; example &lt;- function(n,B=10000) mean(replicate(B,all(sample(n):1:n)))
  &gt; set.seed(0)
  &gt; example(3)
  </code></pre>
  
  <p>Calculated with other programs this should give a value near 2.6662, but in R I keep getting this output:</p>
  
  <pre><code>[1] 1
  There were 50 or more warnings (use warnings() to see the first 50)
  </code></pre>