[R] Generate random numbers up to one

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Tue Mar 6 15:46:54 CET 2007


Núria Martínez wrote:
> Dear all,
>
> I would like to know if there is a simple way to generate random numbers 
> with the constrain that they sum up to one. I am new using R...
>   

The easiest way is to generate them by whatever method and divide by
their sum. e.g. as

(s<-rexp(100))/sum(s)

Are there other constraints, you need the numbers to satisfy? Obviously,
they can't be independent.

-- 
   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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list