If you wanted a discrete uniform from 1-10 use: ceiling(10*runif(1))
if you wanted from 0-12, use: ceiling(13*runif(1))-1
--
View this message in context:
http://r.789695.n4.nabble.com/Simulation-from-discrete-uniform-tp3434980p3939694.html
Sent from the R help mailing list archive at
Why don't you use sample;
sample(1:10,10,replace=TRUE)
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of BSanders
Sent: 26 October 2011 08:49
To: r-help@r-project.org
Subject: Re: [R] Simulation from discrete uniform
If you wanted
Hi
Also , same problem to create discrete uniform Distribution ,
But sample () and runif() not useful to generate discrete uniform .
Ex:
u-round(runif(10*10,min=1,max=10),0)
table(u)
u
1 2 3 4 5 6 7 8 9 10
6 10 9 10 14 6 11 14 12 8
Not useful for large number
OR
#
Hi Serdar,
Take a look at the following:
sample(0:9, 100, replace = FALSE)
Error in sample(0:9, 100, replace = FALSE) :
cannot take a sample larger than the population when 'replace = FALSE'
sample(0:9, 100, replace = TRUE)
[1] 5 6 5 7 3 0 8 4 8 2 2 4 7 6 0 7 0 0 0 7 5 6 3 6 0 9 6 1 2 6 9
?sample
-Oprindelig meddelelse-
Fra: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] På
vegne af cassie jones
Sendt: 8. april 2011 03:16
Til: r-help@r-project.org
Emne: [R] Simulation from discrete uniform
Dear all,
I am trying to simulate from discrete uniform
Dear all,
I am trying to simulate from discrete uniform distribution. But I could not
find any in-built code in R. Could anyone help me please?
Thanks in advance for the time and help.
Cassie
[[alternative HTML version deleted]]
__
Hi:
Suppose X has a discrete uniform distribution on the sample space S = {0, 1,
2, ..., 9}. Then a random sample of size 100 from this distribution, for
example, would be
dus - sample(0:9, 100, replace = TRUE)
# Checks:
table(dus)
lattice::barchart( ~ table(dus), xlim = c(0, 20))
The sample
7 matches
Mail list logo