Skip to content
Prev 369069 / 398500 Next

Joining tables with different order and matched values

I'm repeating my question and hope to find someone to help.


I have been trying for hours but without results, I have done previous suggestions but still struggling.


I believe that join functions in dplyr will do the work but I'm confusing with the correct syntax.


I have 2 tables and I'm trying to have some information from the 1st table to appear in the 2nd table.


let's say this is my 1st table :-
Drug name           indications

 Ibuprofen                Pain

 Simvastatin            hyperlipidemia

losartan                   hypertension



my 2nd table contains the same list of drugs under the first column BUT with different order :-
Drug name       indications


Simvastatin

losartan

Ibuprofen

Metformin

Simply, I want to produce a table like df1 but in the order of the 1st column of my df2.

This would be like this
Drug name       indications


Simvastatin     hyperlipidemia

losartan           hypertension

Ibuprofen       pain

Metformin    N/A


Please note that it is important to keep the order of drugs in df2 as it and to see the appropriate indication of each drug(which is withdrawn from df1) next to it under "indications" column.
Message-ID: <CY4PR15MB130223813A3DEF208EDBCF3EEFEF0@CY4PR15MB1302.namprd15.prod.outlook.com>
In-Reply-To: <CAKVAULPtDFaQpCKq4yP4MqgoTk0qGby_DancBW9QhWR+=W8sew@mail.gmail.com>