mercredi 4 août 2021

random sampling from a table

I have an original table

full_table

patientID    gender     age

hash1        male       25
hash2        male       24
hash3        female     43
hash4        female     45
...

I am trying to create a random subset of the above table using the table below such that I end up with 2x the value in the count column with the following conditions:

summary_table

gender    age     count

male      42      5
female    65      3

Basically, I would like to pull 10 rows from the full_table where age=42 and gender="male" in addition to 6 rows where gender="female" and age=62.

The results could look like this:

patientID    gender     age

hash49       male       42
hash19273    male       42
hash1324     male       42
... *7
hash123      female     62
hash5346     female     62
hash132      female     62
... *3



Aucun commentaire:

Enregistrer un commentaire