One of possible solutions is: generate all the numbers.
num <- rpois(...) num <- round(num/sum(num)*100,0) sum(num) I don't know if it is the best solution, but is one! Leandro Marino -----Mensagem original----- De: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] nome de Peter Dalgaard Enviada em: terça-feira, 8 de julho de 2008 05:12 Para: Richard Pearson Cc: [EMAIL PROTECTED] Assunto: Re: [R] Sum(Random Numbers)=100 Richard Pearson wrote: > Shubha > > Does table(ceiling(runif(100,0,50))) give you something like you want? That's a neat(-ish) solution of Moshe's multinomial formulation. More generally, if p is a vector of probabilities you can simulate independent indicators with cut(runif(N), c(0,cumsum(p)) and then multinomials by tabulation. However, it is inefficient for large N, and awkward if you want replicates, which is why we have rmultinom(). In the present case use rmultinom(1, 100, rep(1/50,50)) -- O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ 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. ______________________________________________ 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.