I am working on a project using medication history of patients, and I want to ask your help for this. The database contains start dates of medication in random order, and I would like to number the medications in order of use.
So I would like to transform:
ID 001 002 003
medA 2001 2005 2003
medB 1999 2000 2015
medC 2019 2014 2000
To:
ID 001 002 003
medA 1 3 2
medB 1 2 3
medC 3 2 1
The real database has 700 subjects and 10+ medications.
Is there a way to do this in R?
Thanks in avance for your help!
NB this is my first post, please let me know if I'm doing something wrong forum-wise :)