I have generated a dataframe which contains 100 rows and 3 columns: one with an x-coordinate, one with a y-coordinate, and one with "level" which is a variable I use as a constraint. I want to randomly sample 10 coordinates from these 100 at Level 1. For this, I have used the sample function in R, randomly selecting 10 rows.
However, some of the coordinates end up being too close to each other, so I want to add a second constraint that says the sample function has to skip at least 5 rows from any selected random row. How do I do this?
This is what I have now:
newdf <- df[sample(which(df$level == 1 ) , 10 ) , ]
Aucun commentaire:
Enregistrer un commentaire