[R] generate a vector of random numbers within confines of certain parameters
jdnewmil at dcn.davis.ca.us
Tue Aug 2 22:08:16 CEST 2016
x <- rnorm( 20000, 5, 2.5 )
The requirement for "random" is ill-specified because it omits mention of which random distribution you want (I assumed normal distribution above).
The requirement for "decimal places" is ill-defined because floating point numbers are internally represented with mantissa and exponent ("scientific notation"), so large numbers have fewer significant "decimal places" in the fraction than small numbers do. For most purposes double precision IEEE754 numbers have more precision than you will need. What gets sticky is if you want to LIMIT the number of decimals... you may need to use the sprintf function and export the data as character values if that is important (which I doubt).
Note that the default behavior of the R console is to PRINT values with four decimals, but the rest of the significant digits are really still there.
Sent from my phone. Please excuse my brevity.
On August 2, 2016 11:56:35 AM PDT, Adrian Johnson <oriolebaltimore at gmail.com> wrote:
>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
>Std. Dev : 2-3
>mean : 4-6
>Is there a method to generate numbers with 6 decimal places under
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help