From: Ravi Varadhan <rvaradha_at_jhsph.edu>

Date: Tue 04 Oct 2005 - 21:09:14 EST

}

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Oct 04 21:19:37 2005

Date: Tue 04 Oct 2005 - 21:09:14 EST

I mean to say: check out "rmultinom" function

? rmultinom

For example,

rmultinom(10,50,prob=rep(1,5))

will give you 10 vectors (arranged as columns of a matrix), each of length 5, sampled from 1:50 and adding up to 50. You can adjust the weights "prob" to draw according to your needs.

Hope this is helpful,

Ravi.

From: r-help-bounces@stat.math.ethz.ch on behalf of Ravi Varadhan
Sent: Tue 10/4/2005 7:03 AM

To: vincent@7d4.com; r-help@stat.math.ethz.ch
Subject: Re: [R] sampling vectors

Your problem is nothing but that of drawing a random sample from a multinomial distribution. Check out the "Multinomial" function.

?Multinomial

Best,

Ravi.

From: r-help-bounces@stat.math.ethz.ch on behalf of vincent@7d4.com
Sent: Tue 10/4/2005 1:59 AM

To: r-help@stat.math.ethz.ch

Subject: Re: [R] sampling vectors

Eric Pante a écrit :

> Hello Listers,

*> I am trying to sample a vector to create a new one of sample length,
**> witha sum equal to the sum of the initial vector:
**> initial = 10, 30, 10 (sum=50)
**> sample example = 5, 35, 10 (sum=50) or 25, 15, 10 (sum=50), etc ...
**> My problem is to control the sum, so it stays constant.
*

f0 = function()

{

s1 = 50;

for (i in 0:s1)

{ s2 = s1 - i; for (j in 0:s2) { s3 = s2 - j; print (c(i,j,s3)); } }

}

(If I have well understood the question) ?
hih

Vincent

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

[[alternative HTML version deleted]]

[[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Oct 04 21:19:37 2005

*
This archive was generated by hypermail 2.1.8
: Sun 23 Oct 2005 - 18:17:28 EST
*