I have two df I want to merge.
df1 looks like this:
CODE    TAX   PRICE   TOTAL
4577    0.9   99.1    100
8965    NA    25      25
7788    1.5   13.5    15
4021    NA    20      20
6987    0.00  40      40
df1 is a dataframe containing codes, tax cost depending on prices and the total (sum) of taxes + prices.
df2 looks like this:
CODE    TAX.CLASS   MEANING
4577     CLASS1     Car
4577     CLASS2     Car
8965     CLASS1     Internet
2635     CLASS1     Computer
7788     CLASS1     Phone
7788     CLASS2     Phone
1258     CLASS1     Water
4021     CLASS1     Food
6987     CLASS1     Gasoline
6987     CLASS2     Gasoline
where each code displays a tax.class and meaning.
I would like to get an output like this:
CODE    MEANING   TAX.CLASS   TAX   PRICE   TOTAL
4577    Car        CLASS2     0.9   99.1    100
8965    Internet   CLASS1     NA    25      25
7788    Phone      CLASS2     1.5   13.5    15
4021    Food       CLASS1     NA    20      20
6987    Gasoline   CLASS1     0.00  40      40
So far I have tried with the answers of these questions:
- How to join (merge) data frames (inner, outer, left, right)?
- How to merge two dataframes in R conditionally (common column, condition)
- Merge 2 dataframes based on condition in R
- Merge Dataframe with conditional statements in R
but it has not worked as I want. The issue basically is to match every code in df1 with the code in df2 but retrieving CLASS1 if there is NA or a TAX value in df1 <= 0.00, on the other hand, retrieve CLASS2 if there is a TAX value in df1 > 0.00 on codes repeated twice.
Any suggestions?
Preferably BaseR.
 
     
    