I am trying to create a frequency table returning the number of unique diagnoses per ID but some IDs were assigned the same diagnosis code multiple times. Here is how my data looks like:
EncounterID Diagnosis
1 a
1 a
1 c
2 a
2 b
3 e
3 e
3 e
Here is what I would like my frequency table to look like:
EncounterID Diagnosis
1 2
2 2
3 1
I am relatively new to R, I figured the first part of the code. Here is the code I have tried, but it is not returning the number of unique diagnoses.
Num_Diag_Per_Enct <- data.table(table(diagn$ENCOUNTER_ID))