I want to generate random frequencies (i.e. frequencies have to equal to 1) to simulate gene frequencies in a population using R. My solution is:
freq<- function(x,y) #random frequency generator, no defined distribution
{rn<-sample(1:y,x)
sum <- sum(rn)
for(i in 1:x){
RG[i]=rn[i]/sum}
return(RG)
}
Any suggestions on how to constrain the sum to a particular value (e.g. the random numbers have to equal 100) before division?