[R] Problems with randomly generating samples

2009-05-13 Thread Debbie Zhang

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


_
Looking to change your car this year? Find car news, reviews and more

e%2Ecom%2Fcgi%2Dbin%2Fa%2Fci%5F450304%2Fet%5F2%2Fcg%5F801459%2Fpi%5F1004813%2Fai%5F859641&_t=762955845&_r=tig_OCT07&_m=EXT
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems with randomly generating samples

2009-05-13 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Debbie Zhang
> Sent: Wednesday, May 13, 2009 8:18 AM
> To: r-help@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
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problems with randomly generating samples

2009-05-13 Thread Ted Harding
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) 
Fax-to-email: +44 (0)870 094 0861
Date: 13-May-09   Time: 16:46:05
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.