I need to generate a vector of random numbers that lay between an upper an lower bound. Each number has it's own bounds - thus the bounds are vectors as well.
Currently I do this with a for loop but there might be a better way.
# Bounds
lb <- c(1,2,3,4)
ub <- c(9,7,5,8)
# Generate rnd numbers, stored in rndnum
rndnum <- runif(1, lb[1], ub[1])
for(i in 2:length(lb))
rndnum <- c(rndnum, runif(1,lb[i], ub[i]))
Aucun commentaire:
Enregistrer un commentaire