Sorry I forgot to talk about the range.

But as an example, range (17,23) works.

In your codes, mean is not exactly 20 and the samples are not integer.
However, what I want is integers with mean 20 exactly.

Any tips?

Thanks

On Thu, Sep 2, 2010 at 12:16 AM, Barry Rowlingson <
b.rowling...@lancaster.ac.uk> wrote:

>  On Thu, Sep 2, 2010 at 7:17 AM, Yi <liuyi.fe...@gmail.com> wrote:
> > Hi, folks,
> >
> > runif (n,min,max) is the typical code for generate R.V from uniform dist.
> >
> > But what if we need to fix the mean as 20, and we want the values to be
> > integers only?
>
>  It's not clear what you want. Uniformly random integers with expected
> mean 20 - but what range? Any range centred on 20 will work, for
> example you could use sample() with replacement. To see the
> distribution, use sample()
>
>  table(sample(17:23,10000,TRUE))
>
>  which gives a uniform distribution of integers from 17 to 23, so the
> mean is 20.0057 for 10000 samples.
>
>  Is that what you want?
>
> Barry
>

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

Reply via email to