Re: [R] Sum(Random Numbers)=100

From: Daniel Malter <daniel_at_umd.edu>
Date: Tue, 08 Jul 2008 03:27:26 -0400


sum.x=sum(x)
while(sum.x!=100)
x=rpois(50,2)

I have tried this, but this can really take some time. In fact, I would suggest an similarly "fraudulent" activity, draw 49 values, and set the last nonrandomly to the difference between 100 and the sum of the 49 values if this difference is a.) nonnegative and b.) not too extreme (say more than three lambdas out). This is "as random" as the previous approach, maybe even more.

Best,
Daniel



cuncta stricte discussurus

-----Ursprüngliche Nachricht-----
Von: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org] Im Auftrag von Shubha Vishwanath Karanth
Gesendet: Tuesday, July 08, 2008 1:59 AM An: r-help_at_stat.math.ethz.ch
Betreff: [R] Sum(Random Numbers)=100

Hi R,  

I need to generate 50 random numbers (preferably poisson), such that their sum is equal to 100. How do I do this?    

Thank you,

Shubha  

This e-mail may contain confidential and/or privileged i...{{dropped:13}}



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.

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. Received on Tue 08 Jul 2008 - 07:30:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Jul 2008 - 08:31:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive