mercredi 17 juin 2020

R code to iteratively and randomly delete entire rows from a data frame based on a column value, and saving as a new data frame each time

Please forgive me if this question has been asked before!

So I have a dataframe (df) of individuals sampled from various populations with each individual given a population name and a corresponding number assigned to that population as follows:

Individual  Population  Popnum
ALM16-014   AimeesMdw   1
ALM16-024   AimeesMdw   1
ALM16-026   AimeesMdw   1
ALM16-003   AMKRanch    2
ALM16-022   AMKRanch    2
ALM16-075   BearPawLake 3
ALM16-076   BearPawLake 3
ALM16-089   BearPawLake 3

There are a total of 12 named populations (they do not all have the same number of individuals) with Popnum 1-12 in this file. What I need to do is randomly delete one or more populations (preferably using the 'Popnum' column) from the dataframe and repeating this 100 times and then saving each result as a separate dataframe (ie. df1, df2, df3, etc). The end result is 100 dfs with each one having one population removed randomly. The next step is to repeat this 100 times removing two random populations, then 3 random populations, and so on.

Any help would be greatly appreciated!!




Aucun commentaire:

Enregistrer un commentaire