lundi 31 octobre 2016

How to generate random numbers from defined ranges in R

I want to generate random numbers in R. Say I have some ranges:

20  3293601
3295601 3653454
3655454 3877785
3879785 4454406
4456406 4772139
4774139 4948406
4950406 5188645
5190645 5641009
5643009 5731188
5733188 5993268...

Definitely, I can first generate sequences of this ranges by seq(start, end) and append all these sequences together. Then I can use sample(sequences, n) to generate random numbers. But the thing is I have many of these ranges, say I have thousand ranges, so it is not very feasible to generate all these sequences. Is there any faster way to generate random numbers in these ranges in R?




Aucun commentaire:

Enregistrer un commentaire