Skip to content
Back to formatted view

Raw Message

Message-ID: <3e64db1f99ce45a1859443137bc16eee@exch-2p-mbx-t2.ads.tamu.edu>
Date: 2016-08-02T19:39:40Z
From: David L Carlson
Subject: generate a vector of random numbers within confines of certain	parameters
In-Reply-To: <CAL2fYnMFX6OBj7Lms5--NHT489eS+pLZBHcPdF-bzSDTPHKDyA@mail.gmail.com>

Try

> set.seed(42)
> x1 <- round(rnorm(20000, 4, 2), 6)
> head(x1)
[1] 6.741917 2.870604 4.726257 5.265725 4.808537 3.787751

Setting the seed makes the sequence reproducible, but if that is not important, you can leave it out. This assumes you want a normal distribution and you want to specify the mean and standard deviation. If you want those to be selected randomly. The following does that using uniform distributions so each mean and standard deviation is equally likely within the range:

> x2 <- round(rnorm(20000, runif(1, 4, 6), runif(1, 2, 3)), 6)
> head(x2)
[1] 4.054289 4.745569 5.795536 6.316750 4.370713 5.586646

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352




-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Adrian Johnson
Sent: Tuesday, August 2, 2016 1:57 PM
To: r-help
Subject: [R] generate a vector of random numbers within confines of certain parameters

Dear group,

I am trying to generate a vector of random numbers for 20K observation.

however, I want to generate numbers (with 6 decimal places) within the range of
Std. Dev : 2-3
mean  : 4-6

Is there a method to generate numbers with 6 decimal places under
these parameters

thank you.
Adrian

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.