mardi 25 février 2020

R randomly select rows until varying sum is met

I am interested in comparing the some values between different sized patches but want to randomly select small patches until their area equals that of a randomly selected large patch. I would then compare the unique count of species between this selection of small patches and the single large patch.

For instance

>df
ID     Type        Area        Species1     Species2
1      Big          50            1            1
2      Big          100           1            0
3      Small        25            0            1
4      Small        50            1            1
5      Small        25            1            1

I would then like to randomly select small patches until their Area sums equal a randomly chosen big patch. Then I would like to compare the unique count of species between this selection and the randomly chosen big patch of equal size. For example

If patch 1 is chosen and the random selector could select either patch 4, or 3+5. The comparison would then be between Unique Count Patch1 =2, Unique Count Patch4 =2, or Unique Count 3+5= 2.

I hope this makes sense. If there any questions I would be happy to reply/update this. Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire