What is difference between replicate n times and generate n directly in sampling of R?
<p>I am asked to "simulate x as an independent identically distributed (iid) normal variable with mean=0, std=1.5 with sample length 500"</p>

<p>I am doing the sampling in following two ways:</p>

<pre><code>set.seed(8402)
X &lt;- rnorm(500, 0, 1.5)
head(X)
</code></pre>

<p>and I got</p>

<pre><code>-1.8297969 -0.1862884 1.4219400 -1.0841421 -1.5276701 1.6159368
</code></pre>

<p>However, if I do</p>

<pre><code>X &lt;- replicate(500, rnorm(1,0,1.5))
head(X)
</code></pre>

<p>and I got</p>

<pre><code>-0.04032755 0.92002552 -2.28001943 -1.36840869 1.49820718 0.06205003
</code></pre>

<p>My question is what is the right way to generate iid normal variable? What is the difference between those two ways?</p>

<p>Many thanks!</p>