[R] runif with weights
Ken Knoblauch
knoblauch at lyon.inserm.fr
Thu May 31 02:59:23 CEST 2007
Not sure why you have set the probability of a 1 to 0 but maybe something
like this might be what you want:
round( ifelse( rbinom(25, 1, 0.4), runif(25, 2, 10), runif(25, 11, 100) ) )
[1] 2 6 34 90 79 71 83 8 47 36 21 32 17 71 3 16 9 65 94 6 30 5 7
10 13
############
I would like to generate 25 numbers from 1 to 100 but I would like to have
some numbers that could be more probable to come out. I was thinking of
the function runif:
runif(25, 1, 100) , but I don´t know how to give more weight to some numbers.
Example:
each number from 2 to 10 has the probability of 40% to come out but the
probability of each number from 11 to 100 to come out is 60%.
--
Ken Knoblauch
Inserm U846
Institut Cellule Souche et Cerveau
Département Neurosciences Intégratives
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.pizzerialesgemeaux.com/u846/
More information about the R-help
mailing list