I would like to give a unique ID number in a data frame (df) based on certain conditions in the df. My df looks like this:
dfin <-
STUDY DRUG FED DOSE TIME CONC
4 0 1 50 2 10
4 0 1 60 4 25
5 1 1 10 5 20
12 0 0 50 2 10
And so on. I want to add a unique ID number for each unique combination of STUDY, DRUG, FED, DOSE
. The output for the above should be like this:
dfout <-
STUDY DRUG FED DOSE TIME CONC ID
4 0 1 50 2 10 1
4 0 1 60 4 25 2
5 1 1 10 5 20 3
5 1 0 10 5 25 4
12 0 0 50 2 10 5
I would need help on how to do this in R.