mercredi 11 septembre 2019

How to randomly divide interval into non overlapping, spaced bins of equal length

I have an interval from for example from 1 to 671. I would like to divide it into 5 random non-overlapping bins of length 50 but also spaced with min 51.

interval <- 1:671 

Result (this is an example as the bins should be random but within interval, equal length and spaced as defined):

bin1 <- 3:52
bin2 <- 103:152
bin3 <- 209:258
bin4 <- 425:474
bin5 <- 610:659

I would preferentially like the output to be a dataframe(bin, startOfbin, endOfbin), but other types like list would be also ok.

I am currently writing a function in R that would use this sampling and I can come up with sensible solution. Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire