Ettinger, Nicholas
2007-Nov-30 19:48 UTC
[R] How to choose 3 random numbers from 1 up to 9?
Hello all, For the not-so-deeply-mathematically/statistically-literate, what is the simplest command with which to choose three "random" numbers from the integer list 1 up to 9? After reading the ".Random.seed" help page along with several others, it seems like the one simple choice might be: round(rnorm(1:3,4.5,1)) ?? Any thoughts? Suggestions or better ideas most welcome! Thank you. --Nick Ettinger
x <- 1:9 sample(x,3, replace=TRUE)> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Ettinger, Nicholas > Sent: Friday, November 30, 2007 2:48 PM > To: r-help at r-project.org > Subject: [R] How to choose 3 random numbers from 1 up to 9? > > Hello all, > > For the not-so-deeply-mathematically/statistically-literate, > what is the simplest command with which to choose three > "random" numbers from the integer list 1 up to 9? > > After reading the ".Random.seed" help page along with several > others, it seems like the one simple choice might be: > > round(rnorm(1:3,4.5,1)) > > ?? > > Any thoughts? Suggestions or better ideas most welcome! > > Thank you. > --Nick Ettinger > > ______________________________________________ > R-help at 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. >
See ?sample Uwe Ligges Ettinger, Nicholas wrote:> Hello all, > > For the not-so-deeply-mathematically/statistically-literate, what is the > simplest command with which to choose three "random" numbers from the > integer list 1 up to 9? > > After reading the ".Random.seed" help page along with several others, it > seems like the one simple choice might be: > > round(rnorm(1:3,4.5,1)) > > ?? > > Any thoughts? Suggestions or better ideas most welcome! > > Thank you. > --Nick Ettinger > > ______________________________________________ > R-help at 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.
Ettinger, Nicholas wrote:> Hello all, > > For the not-so-deeply-mathematically/statistically-literate, what is the > simplest command with which to choose three "random" numbers from the > integer list 1 up to 9??sample as in > sample(1:9, 3) # your result may vary! [1] 4 7 1 or, if you need replacement, set argument replacement = TRUE Also, look at ?set.seed for a way to make sure you get the same set of pseudorandom numbers of reproducibility of your work is required. HTH G> > After reading the ".Random.seed" help page along with several others, it > seems like the one simple choice might be: > > round(rnorm(1:3,4.5,1)) > > ?? > > Any thoughts? Suggestions or better ideas most welcome! > > Thank you. > --Nick Ettinger > > ______________________________________________ > R-help at 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%