Re: [R] How to generate integers from uniform distribution with fixed mean

2010-09-04 Thread Yi
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

Re: [R] How to generate integers from uniform distribution with fixed mean

2010-09-04 Thread Barry Rowlingson
On Sat, Sep 4, 2010 at 8:07 AM, Yi liuyi.fe...@gmail.com wrote: 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. The samples *are* integers. sample(17:23,1,TRUE) returns integers.

Re: [R] How to generate integers from uniform distribution with

2010-09-04 Thread Ted Harding
There is still ambiguity (and I think some misunderstanding) in your query! First, Barry's code does yield integers as the values in the sample. As a smaller illustrative example: x - sample(17:23,20,TRUE) will give results like x # [1] 21 17 23 21 17 17 19 18 17 17 17 22 20 23 20 20 18

Re: [R] How to generate integers from uniform distribution with

2010-09-04 Thread Ted Harding
On 04-Sep-10 19:27:54, Yi wrote: Enh, I see. It totally makes sense. Thank you for your perfect explanation. Enjoy the long weekend~ Yi You're welcome! Earlier I tried an experiment with rejection sampling, which seems to work well for the case where you want mean of the sampled values to

[R] How to generate integers from uniform distribution with fixed mean

2010-09-02 Thread Yi
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? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org

Re: [R] How to generate integers from uniform distribution with fixed mean

2010-09-02 Thread Barry Rowlingson
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