mercredi 25 avril 2018

Best way to pick random elements from an array with at least a min diff in R

I would like to randomly choose from an array a certain number of elements in a way that those respect always a limit in their reciprocal distance. For example, having a vector a <- seq(1,1000), how can I pick 20 elements with a minimum distance of 15 between each other?

For now, I am using a simple iteration for which I reject the choice whenever is too next to any element, but it is cumbersome and tends to be long if the number of elements to pick is high. Is there a best-practice/function for this?




Aucun commentaire:

Enregistrer un commentaire