I am trying to sample between a range of values as part of a larger loop in R. As the loop progresses to each row j
, I want to sample a number between the value giv
You might not need to loop through. If you want need is something between start and end, it's almost equivalent to sampling something between 0-1 and multiplying that by the range.
df %>% mutate(sampled = start + round((end-start)*runif(nrow(.))))
Regarding the updating, dependencies you mentioned in your comment: sounds a bit complicated. Quick thought: Might be faster to sample a lot of times and choose one that fits your criteria.