Skip to content
Back to formatted view

Raw Message

Message-ID: <XFMail.090513164609.Ted.Harding@manchester.ac.uk>
Date: 2009-05-13T15:46:09Z
From: (Ted Harding)
Subject: Problems with randomly generating samples
In-Reply-To: <COL113-W67658B49339B079E664364C7610@phx.gbl>

On 13-May-09 15:18:05, Debbie Zhang 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)
>  
> Thanks for help
> Debbie

One possibility is

  nsamples <- 1000
  sampsize <- 100
  Samples <- matrix(rnorm(nsamples*sampsize,0,1),nrow=nsamples)

Then each row of the matrix Samples will be a sample of size 'sampsize',
the i-th can be accessed as Samples[i,], and there are 'nsamples' rows
to choose from.

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 13-May-09                                       Time: 16:46:05
------------------------------ XFMail ------------------------------