vendredi 8 juillet 2022

Is there a way of selecting all records of a certain ID after randomly selecting the IDs?

I have a number of values per ID in this format:

ID  Var1 Var2 Var3
1    A     A    C
1    C     B    B
1    B     D    A
2    C     B    C
2    D     B    A
2    D     A    D
3    A     D    B
3    B     C    C
3    C     B    A
4    A     A    D
4    C     B    C
4    B     B    A
5    D     B    B
5    A     C    C
5    D     C    C

I want to randomly select IDs but keep all values per ID, so for example, if I wanted to get 2 random IDs; the outcome would look like this:

ID  Var1 Var2 Var3
2    C     B    C
2    D     B    A
2    D     A    D
5    D     B    B
5    A     C    C
5    D     C    C

Giving me, ID 2 & 5.




Aucun commentaire:

Enregistrer un commentaire