[R] Simulation
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed May 13 18:36:13 CEST 2009
Barry Rowlingson wrote:
> On Wed, May 13, 2009 at 4:26 PM, Gábor Csárdi <csardi at rmki.kfki.hu> wrote:
>
>> On Wed, May 13, 2009 at 5:13 PM, Debbie Zhang <debbie0621 at hotmail.com> wrote:
>>
>>> Dear R users,
>>>
>>> Can anyone please tell me how to generate a large number of samples in R, given certain distribution and size.
>>>
>>> For example, if I want to generate 1000 samples of size n=100, with a N(0,1) distribution, how should I proceed?
>>>
>>> (Since I dont want to do "rnorm(100,0,1)" in R for 1000 times)
>>>
>> Why not? It took 0.05 seconds on my 5 years old laptop.
>>
>
> Second-guessing the user, I think she maybe doesn't want to type in
> 'rnorm(100,0,1)' 1000 times...
>
> Soln - "for" loop:
>
> > z=list()
> > for(i in 1:1000){z[[i]]=rnorm(100,0,1)}
>
> now inspect the individual bits:
>
> > hist(z[[1]])
> > hist(z[[545]])
>
> If that's the problem, then I suggest she reads an introduction to R...
i'd suggest reading the r inferno by pat burns [1], where he deals with
this sort of for-looping lists the way it deserves ;)
vQ
[1] http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
More information about the R-help
mailing list