Skip to content
Back to formatted view

Raw Message

Message-ID: <941871A13165C2418EC144ACB212BDB0BEB3C5@dshsmxoly1504g.dshs.wa.lcl>
Date: 2009-05-13T15:36:27Z
From: Nordlund, Dan (DSHS/RDA)
Subject: Problems with randomly generating samples
In-Reply-To: <COL113-W67658B49339B079E664364C7610@phx.gbl>

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Debbie Zhang
> Sent: Wednesday, May 13, 2009 8:18 AM
> To: r-help at r-project.org
> Subject: [R] Problems with randomly generating samples
> 
> 
> 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
> 
> 

How about

samples <- rnorm(1000*100,0,1)
dim(samples) <- c(1000,100)

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204