[R] generate random number

Bill.Venables@CMIS.CSIRO.AU Bill.Venables at CMIS.CSIRO.AU
Wed Mar 21 08:44:31 CET 2001



| -----Original Message-----
| From: Kaspar Pflugshaupt [mailto:pflugshaupt at cirsium.ethz.ch]
| Sent: Wednesday, 21 March 2001 17:32
| To: Yu-Ling Wu
| Cc: r-help mailing list
| Subject: Re: [R] generate random number
| 
| 
| On Wednesday 21 March 2001 02:15, Yu-Ling Wu wrote:
| > Hi,
| >
| > I want to pick 3 "integer" random numbers from 1 to
| > 10. How to do this?
| 
| as.integer(runif(3)*10+1)

Eh?  There is a simpler way:

sample(1:10, 3)
sample(1:10, 3, rep=T)

depending on what is meant.  The second is equivalent to yours.


| 
| Cheers
| 
| Kaspar Pflugshaupt
| 
| 
| -- 
| 
| 
| Kaspar Pflugshaupt
| Geobotanical Institute
| ETH Zurich, Switzerland
| 
| http://www.geobot.umnw.ethz.ch
| mailto:pflugshaupt at geobot.umnw.ethz.ch
| -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
| -.-.-.-.-.-.-.-.-
| r-help mailing list -- Read 
| http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
| Send "info", "help", or "[un]subscribe"
| (in the "body", not the subject !)  To: 
| r-help-request at stat.math.ethz.ch
| _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
| _._._._._._._._._
| 
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list