Skip to content
Prev 370149 / 398503 Next

Creating two groups of random numbers

I'd do it this way ... let me know if you need explanations.

minSize <- 15
maxSize <- 100
minSample <- 0.1
maxSample <- 0.8

# setup dataframe with totals, and cases as fractions
myStudies <- data.frame(study = 1:Nstudies,
                        cases = runif(Nstudies,
                                      min = minSample,
                                      max = maxSample),
                        total = sample(minSize:maxSize,
                                       Nstudies,
                                       replace = TRUE))

# convert case fractions of totals to integers
myStudies$cases <- round(myStudies$cases * myStudies$total)


Cheers,
Boris