[R] generate random number

Friedrich Leisch Friedrich.Leisch at ci.tuwien.ac.at
Wed Mar 21 08:50:12 CET 2001


>>>>> On Wed, 21 Mar 2001 08:31:52 +0100,
>>>>> Kaspar Pflugshaupt (KP) wrote:

  > 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)


better :

sample(1:10, size=3, replace=TRUE)

[because also working on general vectors, not only integers, as e.g.,

sample(letters, size=3, replace=TRUE)

]

-- 
-------------------------------------------------------------------
                        Friedrich  Leisch 
Institut für Statistik                     Tel: (+43 1) 58801 10715
Technische Universität Wien                Fax: (+43 1) 58801 10798
Wiedner Hauptstraße 8-10/1071      Friedrich.Leisch at ci.tuwien.ac.at
A-1040 Wien, Austria             http://www.ci.tuwien.ac.at/~leisch
-------------------------------------------------------------------

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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