Spelling counts. Your "want" shows "Rti, levo" and "Rti, clr, levo". You data shows exactly zero examples of "Rti" in the data. "rti" yes. You also show wanting different cases of Rti and Clr depending on where it appears (apparently). We do not have your data or understanding of anything other than what you provide. So from the provided example I would not presume to create that "want" as the values shown are different.
One of the things that is going to be needed is to address order and the way your data is currently there is going to be some difficulty telling if ''rti, lit" and "lit, rti" are supposed to be the same or note. Personally first step is to get ONE observation per "patient", date, medication. I.e. fix this so it is two observations, and similarly for any other combinations.
Also, do we have to guess the studyid supposedly identifies a "patient"?