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 space comprises the first argument of sample(), the sample size
is the second argument, and the replace = TRUE argument allows an element of
the sample space to be selected more than once.
HTH,
Dennis
On Thu, Apr 7, 2011 at 6:15 PM, cassie jones
<cassiejones26@gmail.com>wrote:
> 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]]
>
> ______________________________________________
> R-help@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.
>
[[alternative HTML version deleted]]
?sample -----Oprindelig meddelelse----- Fra: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] P? vegne af cassie jones Sendt: 8. april 2011 03:16 Til: r-help at r-project.org Emne: [R] Simulation 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]] ______________________________________________ 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.
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 # for generate large number dus <- sample(0:9, 100, replace = FALSE) Error in base::sample(x, size, replace = replace, prob = prob, ...) : cannot take a sample larger than the population when ''replace = FALSE'' #### DO you have any suggestion my question ? Need to generate 1000*10 number from 1:250 with discrete uniform distribution ? Regards, Serdar [[alternative HTML version deleted]]
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 Nabble.com.