I have a similar question to counting unique factors in r, however the solutions provided do not work for my data.
My data is organised by drug, with pateint information included in the df as variables as opposed to the patient being the row unit.
Sex ID
drug x F Jane
drug x F Mary
drug x M Philip
drug x F Jane
drug x F Jane
drug x M Philip
drug x M John
drug x M Philip
drug x F Jane
drug x M Philip
I have 4 unique IDs and I would like to know the gender split across these 4 ids, which should be
F M
2 2
But all the code I try gives me back the number of drugs for each gender e.g,
F M
5 5
Could anybody help me out with this please? When I use the previous help I get a list of unique IDs with sex listed as 50.