I am working with R and I have a dataset that looks like this...
group col_2 col_3 col_4
A p_m 12 21
A q_x 11 21
A i_z 13 22
A q_z 11 24
A p_x 14 25
A i_m 15 26
A q_m 17 28
A p_x 16 29
A i_z 12 23
A q_m 14 23
A q_x 13 25
A p_z 11 25
A i_z 15 26
A q_m 17 28
A q_x 14 29
A p_x 13 30
A i_m 15 26
A q_m 17 28
A p_x 16 29
A i_z 12 23
A q_x 13 25
A p_z 11 25
A i_z 15 26
A q_m 17 28
A q_z 11 24
A p_x 14 25
A i_m 15 26
A q_x 11 21
A i_z 13 22
A q_z 11 24
A p_x 13 30
A i_m 15 26
A q_m 17 28
A p_x 16 29
A i_z 12 23
Ok, so I need to randomly select 12 rows based on col_2. I need 6 random rows that start with a "p" in col_2 and 6 random rows that start with a "q" in col_2. I have tried different things with sample_n, but I don't find a way to specifically select 6 and 6 from the different codes.
Any help would be great.